![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
In a table I have the sentence-length of convicted given in days (one year = 360 days, one month = 30 days). In a report I want to convert these days to normal language, so f.ex 420 days would be 1 year and 2 months. The code should be pretty straightforward, I thought, but the result seems like a Paradox - at least to me. Here's the code: vNumberDays = number(Field.Value) ; f.ex 420 ;To get the years: vNumberYears = floor(vNumberDays/360) vLongIntYears = longInt(vNrÅr) ;And the months: vNumberMonths = fraction(vNumberDays/360)*12 vLongIntMonths = longInt(vNumberMonths) This code works very well, EXCEPT in one case: If vNumberDays = 390. In this case vNumberMonths will be 1.00 - and it is. However longInt(vNumberMonths) returns 0 (not 1, like it should). I have tested this on two different machines, both with the same error. If vNumberDays = 750 you should expect the same error, if it was consistent, but in this case the result is correct.... If I change vLongIntMonths = longInt(vNumberMonths) to vLongIntMonths = longInt(vNumberMonths+0.01) or to vLongIntMonths = longInt(round(vNumberMonths,0)) the result is correct. So it seems to me that Paradox feels that 1,00 really is something like 0.9999... Problem is: You don't know when Paradox is of this opinion. Can't I trust it? Do I always have to put in some rounding to be safe? Jostein Bakke |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Thanks Bertil, mod() has not "been in my box", but I see it will work well. However, why is it that I dont have to compensate for effects of binary calculations when I use mod()? Or more to the point: How should I have known this difference between the two methods? Jostein |
#5
| |||
| |||
|
|
In a table I have the sentence-length of convicted given in days (one year = 360 days, one month = 30 days). In a report I want to convert these days to normal language, so f.ex 420 days would be 1 year and 2 months. The code should be pretty straightforward, I thought, but the result seems like a Paradox - at least to me. Here's the code: vNumberDays = number(Field.Value) ; f.ex 420 ;To get the years: vNumberYears = floor(vNumberDays/360) vLongIntYears = longInt(vNrÅr) ;And the months: vNumberMonths = fraction(vNumberDays/360)*12 vLongIntMonths = longInt(vNumberMonths) This code works very well, EXCEPT in one case: If vNumberDays = 390. In this case vNumberMonths will be 1.00 - and it is. However longInt(vNumberMonths) returns 0 (not 1, like it should). |
![]() |
| Thread Tools | |
| Display Modes | |
| |