Jump to content

Is there a RoundTo digits function in the RTL?

Recommended Posts

the built-in javascript functions are located at Espruino.System unit, 


It would really handy if we had a kinda global Utils.pas, just to reference.


{ rounds a floating-point value to a specified digit }
function RoundTo(x: float; digits: integer) : float;
asm @Result=parseFloat((@x).toFixed(@digits)) end;

Link to post
Share on other sites


the built-in javascript functions are located at Espruino.System unit,

Isn't that just for Epruiono boards? Are all of those functions available in classical browsers?


Yes, the units Espruino.* are solely for the Espruino board (software). It features a slightly limited subset of JavaScript and describes the API to access the hardware. Ideally, it should not contain other code.


General code like the one that can be found in warleyalex post should go to System.* units or be covered by the underlying DWScript API.


Unfortunately, it is not (yet) part of this, which means it must be added in the future. Until then, one can use what has been written above.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...