Martin,
Beautiful your work. Thanks a lot for your app.
Performing some calculations on a script I missed two simple functions:
- Int trunc (value): Returns only the integer part with his sign of a number
- Float frac (value): Returns only the fractional part of a number
Sorry if there is already some way to get it, but I searched and could not find it.
Ademir
Script functions trunc and frac
Moderator: Martin
Re: Script functions trunc and frac
Hi,
Thanks, glad you like Automagic!
You could use function floor, ceil or round to get the nearest integer value, technically it's still a floating point number so will display as XYZ.0.
v=1.24;
a=floor(v);
If you want to get the integer part formatted without decimal places I recommend to use an inline script to define the format you need:
formatted_without_decimal_places = "{a,numberformat,0}";
Regards,
Martin
Thanks, glad you like Automagic!
You could use function floor, ceil or round to get the nearest integer value, technically it's still a floating point number so will display as XYZ.0.
v=1.24;
a=floor(v);
If you want to get the integer part formatted without decimal places I recommend to use an inline script to define the format you need:
formatted_without_decimal_places = "{a,numberformat,0}";
Regards,
Martin
-
- Posts: 2
- Joined: 26 Oct 2015 14:30
Re: Script functions trunc and frac
Hi,
I did some testing and found that the function round gives me the result I want.
Different than the definition says (that it rounds), it is only truncating... exactly what I need.
For example, both 3.1 and 3.9, results in pure 3.0
Thanks,
Ademir
I did some testing and found that the function round gives me the result I want.
Different than the definition says (that it rounds), it is only truncating... exactly what I need.
For example, both 3.1 and 3.9, results in pure 3.0
Thanks,
Ademir
Re: Script functions trunc and frac
Hi,
Are you sure that round truncates the value? On my test devices 3.9 is rounded to 4.0. Could you share your script so I can test it on my device?
Regards,
Martin
Are you sure that round truncates the value? On my test devices 3.9 is rounded to 4.0. Could you share your script so I can test it on my device?
Regards,
Martin