Rounding a Float

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
MJU20
Posts: 243
http://meble-kuchenne.info.pl
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Rounding a Float

Post by MJU20 »

In this topic: https://www.matrixtsl.com/mmforums/view ... 794#p95329 someone asked how to round a Float to a certain amount of decimals.

This isn't fixed yet?
If I round a float to 1 decimal and then convert it to a string, I still get 6 decimals.

medelec35
Matrix Staff
Posts: 1450
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 509 times
Been thanked: 472 times

Re: Rounding a Float

Post by medelec35 »

The easiest way to round to one decimal place for example is

Code: Select all

StringVar = FloatToString$ (FloatVar,1)
It will also round up to the nearest decimal place.
I'm sure that works well.
Martin

Steve-Matrix
Matrix Staff
Posts: 1249
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: Rounding a Float

Post by Steve-Matrix »

It is also relatively easy to work around by first multiplying (or dividing) by 1000 (or whatever factor you want), then rounding to the nearest integer, and then dividing (or multiplying) by the same factor.

Post Reply