Any Command to Round to certain amount of Digits?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1031
Joined: Sun Feb 14, 2010 7:11 pm

Any Command to Round to certain amount of Digits?

Post 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.

plouf
Posts: 254
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

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

Post 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))
Christos

Bugala
Posts: 1031
Joined: Sun Feb 14, 2010 7:11 pm

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

Post by Bugala »

Thanks, that is pretty good already.

Post Reply