Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculated field, < Zero always rounds 1

Status
Not open for further replies.

dpav29

Technical User
Aug 3, 2001
155
US
All,
I've read what seems like 100 posts related to rounding problems. . .learned some things, but haven't found quite what I'm looking for.
The table fields and associated form fields are formatted to accept the numbers I need (mostly decimals and many less than zero i.e. 0.1655) If I type them in manually they save as entered. However, these are calulated fields , and the calculated results A) always round, and B)less than zero always shows as zero (even though i have fixed fields with four decimal spaces. The calculations are simple: Me.BSDose = Me.Difference \ 100 (usually small numbers like 26\100 which should be .26

So. . why would the calculation produce a rounded result even if the fields are fomatted correctly? Thanks for any help!

Dave
 
How are ya dpav29 . . .

Have you set the [blue]Format[/blue] property of the calculated controls?

Calvin.gif
See Ya! . . . . . .
 
Yes. . .they are formatted the same way, but will not produce a result less than zero, and if greater than zero, it rounds to the whole number. . no decimals.
 
Could the field be defined as integer or long, you need to use float or decimal?
 
The fields in the table are formatted as double, but i've also tried decimal (i don't see float anywhere). The form fields, both bound and the unbound calculated fields are fomatted as standard, but i've also tried fixed and i have decimal places set at 4 everywhere.

I've seen some posts the reference some kind of workaround with a multiply by 100 and then divide by 100 after the results. . . i guess mine would look something like (((Me.BSDose = Me.Difference \ 100) * 100) \100))

not sure how or why something like that would work!
 
dpav29 . . .

Try the following in the [blue]Format[/blue] property of one of the unbound textboxes:
Code:
[blue]#,##0.0000[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks for trying Aceman, but that didn't do it! I also tried removing all the "if" statements so it was just a simple calculation (A\B), but. . .same bizarre problem!
 
I think we are missing something here. You are doing integer division. There is a difference between \ and /

?10/3
3.333333

?10\3
3
 
Well. . .that's news to me! I had it with \. At first try, it didn't change anything, but i've switch formats so many times, that might be the problem at this point.

How would you say the formats should be set. Im calculating using an unbound field (which is populated useing a fomula from a bound field) divided by 100 and putting the result into a bound field. Like this example

Blood Sugar: 250 (bound field) After update event: if Blood sugar > 180 Then me.difference = blood sugar - 180 else me.difference = 0
So in this example, the calulated value of the unbound "difference" field is 70
Then the lost focus even says: me.difference / 100 (or 70/100 which should result in .7
That is where the trouble is. . everything i have tried results in zero (if the result is less than zero), or is rounded (if the result is > than zero

sorry for so much detail just to ask you your opinion about how these fields should be formatted!

Thanks for helping!
 
Thanks for all your help! I got it working by formatting the unbound fields as Text when using division (and using the proper operand /).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top