Trick to use Rounded Floats
Posted: Tue Oct 29, 2002 10:26 pm
Code updated For 5.20+
Restored from previous forum. Originally posted by MrVainSCL.
Hi @ all
I searches a way to use rounded floats (add, div and more) in an app... so i have had following idea...
In order to round a value, you can use the Int() command. This command rounds the number to an integer like following example:
If you want maintain however two right-of-comma positions, you can use a small trick - you have to shift the comma before
Then you have to round this val with Int() command:
Now we have all muliplied by the factor 100 to get large numbers - thus we divide it again by 100
Now i will follow up with an small example:
Restored from previous forum. Originally posted by MrVainSCL.
Hi @ all
I searches a way to use rounded floats (add, div and more) in an app... so i have had following idea...
In order to round a value, you can use the Int() command. This command rounds the number to an integer like following example:
Code: Select all
tmp1 = Int(102.314) ; Result will be = 103
tmp2 = Int(107.241) ; Result will be = 107
Code: Select all
tmp1 = 102.314 * 100 ; Result will be = 10231.4
tmp2 = 107.241 * 100 ; Result will be = 10724.1
Code: Select all
tmp1 = Int(10231.4) ; Result will be = 10231
tmp2 = Int(10724.1) ; Result will be = 10724
Code: Select all
tmp1 = 10231 / 100 ; Result will be = 102.31
tmp2 = 10724 / 100 ; Result will be = 107.24