FloatToStr
-
- Posts: 41
- Joined: 31 Mar 2012 19:13
FloatToStr
The FloatToStr conversion needs to be modified so that it will round to a set number of decimal points.
- aleksa.jovanovic
- Posts: 526
- Joined: 30 Jun 2015 08:48
Re: FloatToStr
Hi,
Depending on which language you are using it can be done in different ways.
For example in C it would look something like this
In Basic or Pascal it would look something like this
var res : char;
Of course this will not round the number, but just show it in a desired way (it will cut off unwanted digits).
As for the rounding, say for example that you want the number 15.68 to become 15.7, You can make an if function that will look for the second decimal character and if its higher than 5 it will increase the previous decimal by 1, if it's lower than 5 it will not. Just my thought.
I will forward the idea for the function upgrade to our software development team.
Best regards,
Aleksa
Depending on which language you are using it can be done in different ways.
For example in C it would look something like this
Code: Select all
sprintf(lux_value_string, "%5.1f", value);
Ltrim(&lux_value_string);
In Basic or Pascal it would look something like this
var res : char;
Code: Select all
FloatToStr(value,lux_value_string);
res := strchr(lux_value_string, '.');
lux_value_string[res+2] := 0;
Ltrim(lux_value_string);
lux_value_string[7] := 0;
As for the rounding, say for example that you want the number 15.68 to become 15.7, You can make an if function that will look for the second decimal character and if its higher than 5 it will increase the previous decimal by 1, if it's lower than 5 it will not. Just my thought.
I will forward the idea for the function upgrade to our software development team.
Best regards,
Aleksa