![]() |
Rounding float numbers to 2 decimal places - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: How-To & Tutorials (https://www.boriel.com/forum/forumdisplay.php?fid=13) +---- Thread: Rounding float numbers to 2 decimal places (/showthread.php?tid=2537) |
Rounding float numbers to 2 decimal places - rbiondi - 12-29-2023 Hello, I need to round or at least truncate a Float variable to 2 decimal places. Do you know how this could be accomplished since there's no ROUND function? Thank you very much, Rogerio RE: Rounding float numbers to 2 decimal places - boriel - 12-29-2023 There is a trick for that which can be accomplished in several ways. Here's an example of a ROUND function (explained in the ZX Spectrum Manual): Code: FUNCTION Round(n as Float, decimals as UByte = 0) AS Float Use with Round(number, digits) I'll include it in the math library. RE: Rounding float numbers to 2 decimal places - rbiondi - 12-31-2023 Thank you very much! A sugestion would be adding an optional parameter to str$ function: Code: dim floatnum as Float = 0.135[/font][/size][/color] >> prints 0.13 |