Page 1 of 1

Any Command to Round to certain amount of Digits?

Posted: Fri May 13, 2022 10:15 am
by Bugala
Just looked through Hollywood Math library, and at least none got in to my eye as making it possible to Round to some certain digits.

like lets say I am making software using Euros, and then I calculate some percentage from the sum, which could result for example 12.3456

Since Euros go only to two digits, I would naturally want to do Round(Eur), only up to two digits, making it become 12.35.

This can of course be done by the following:

Code: Select all

EURsum = Round(EURsum * 100)
EURsum = EURsum / 100
But I was wondering if there isnt some command which would let me simply do it like:

Code: Select all

RoundToDigits(EURsum, 2)
Meaning EURsum would be rounded up to 2 digits.

Re: Any Command to Round to certain amount of Digits?

Posted: Fri May 13, 2022 1:08 pm
by plouf
FormatStr , make string out but has little difirence to you (you work with string) and easy transformed back to number too

Code: Select all

pi=3.14159265359
DebugPrint(FormatStr("%.2f", Pi))

Re: Any Command to Round to certain amount of Digits?

Posted: Fri May 13, 2022 1:56 pm
by Bugala
Thanks, that is pretty good already.