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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

still need decimal help

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Thanx for the answer, but I still can't seem to get it right. Would you please post a sample code to show me how to do this.

For those wo don't know my problem, delphi rounds off my numerics 2.00 becomes 2 and 2.30 becomes 2.3. This is bad when trying to calculate money $2.00 + $2.50 = $2.5

Please help, I'm about to loose my rocker!

Hennie
 
2.5 is the same as 2.50, it's just a different display format. So, it doesn't matter if Delphi stores it as 2.5 (in fact, that's the only way it can store it unless you change to a string!). When you are displaying it, you need to use FormatFloat('0.00',yourNumber) to convert it to a string, or if you are displaying it from a database field you can use TFloatField's displayformat parameter to pad it with the extra zero.

I would recommend using the currency data type and money fields in your database for storing and using money values, too. That won't help your formatting but it will store numbers more accurately so you don't get penny rounding errors. TealWren
 
Remeber to use the same number of decimals when adding and subtracting etc using floatvalues...

There is a "float" bug in Delphi. Andreas Nordlund
Software developer
 
How would you use the same number of decimals when adding and subtracting? TealWren
 
It's something i've heard from the Delphi team when visited Borland San Diego conferecnce.

I haven't tested it myself... Andreas Nordlund
Software developer
 
Maybe they meant the same precision of float values - like not mixing currency/double/etc.

TealWren
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top