Jump to content
markus_ja

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;
begin
asm @Result=parseFloat((@x).toFixed(@digits)) end;
end;

Share this post


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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×