Rounding a Float

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
MJU20
Posts: 349
http://meble-kuchenne.info.pl
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 99 times
Been thanked: 69 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: 1999
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 630 times
Been thanked: 668 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: 1517
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 212 times
Been thanked: 351 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