Hi,
I have a decimal like 0.9876
I want to round this two digits after the point: 0.99
I read about the floor, ceil and round - funktion
But no function gives me what I want.
Whats the solution?
-Lars
Hi,
I have a decimal like 0.9876
I want to round this two digits after the point: 0.99
I read about the floor, ceil and round - funktion
But no function gives me what I want.
Whats the solution?
-Lars
[quote=160923:@Lars Lehmann]Hi,
I have a decimal like 0.9876
I want to round this two digits after the point: 0.99
I read about the floor, ceil and round - funktion
But no function gives me what I want.
Whats the solution?
-Lars[/quote]
[code] dim d as double
d=ceil(0.9876*100)/100
msgbox str(d)[/code]
You will need to decide when using Floor and Ceil is necessary. For instance, when the third decimal > 5 use Ceil, and otherwise use Floor, so 0.9876 gives 0.99 and 0.9846 gives 0.98.
lol there’s no ready function?
I’ve probably bite the bullet and write my own function
Of course there is: Round. But you’ll still have to temporarily “move” the decimal like MIchel does.
Or you could use Format, but you’ll have to convert it back to a double, if needed :
dim d as double
d = Val(Format(0.9876,"#####0,##"))
[quote=160943:@Lars Lehmann]lol there’s no ready function?
I’ve probably bite the bullet and write my own function :/[/quote]
What is wrong with the two lines I posted ? ? ?
nothing @Michel Bujardet
Thanks! I only thought theres a build-in function
[quote=161282:@Lars Lehmann]nothing @Michel Bujardet
Thanks! I only thought theres a build-in function ;)[/quote]
From what I can see, Round http://documentation.xojo.com/index.php/Round is exactly that. Except you cannot decide which kind of rounding you apply. I think in particular about such things as the kind of rounding used for petty cash.