Jump to content


Photo

Is there a RoundTo digits function in the RTL?


  • Please log in to reply
3 replies to this topic

#1 markus_ja

markus_ja
  • Members
  • 319 posts
  • LocationAustria

Posted 16 March 2016 - 02:01 PM

Hello,

 

I need to round a float value to a fixed number of digits. Is such function already present in the RTL?

 

e.g.:

RoundTo(aValue: Float; aDigit: Integer)

 

http://docwiki.embar...em.Math.RoundTo



#2 Laksekjønn

Laksekjønn
  • Members
  • 440 posts

Posted 16 March 2016 - 06:36 PM

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;


#3 Igor Savkic

Igor Savkic
  • Members
  • 185 posts

Posted 17 March 2016 - 01:52 AM

> 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?



#4 Christian-W. Budde

Christian-W. Budde
  • Members
  • 334 posts
  • LocationGermany

Posted 18 March 2016 - 06:59 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users