[Pas2js] Built-in helper methods for Double type

warleyalex warleyalex at yahoo.com.br
Wed Sep 4 13:23:04 CEST 2019

I came across this situation, when translating to pas2js:

 // Determine X and cut to 2 decimals
  x = (Math.sin(rad) * r).toFixed(2);

It would be nice if pas2js could extend the built-in Number methods for the
type Double, Integer, for instance: syntax something like:

  x: string;
  r, rad: Double;
   x:= (sin(rad) * r).toFixed(2);

struggling how to achieve this situation, an workaround would be:

I had to define an external class at the system unit, math section and a
public single function:

  TJSNumber = class external name 'number'
    function toString(radix: integer = 0): String;
    function toFixed(fractionDigits: integer = 0): string;
    function toExponential(fractionDigits: integer = 0): string;
    function toPrecision(precision: integer): string;

function NumberTo(const aNumber: Double): TJSNumber; external name ' ';

and then

// Determine X and cut to 2 decimals
x := NumberTo(sin(10.1) * 2.5).toFixed(2); // $mod.x =  (Math.sin(10.1) *

Sent from: http://pas2js.38893.n8.nabble.com/

More information about the Pas2js mailing list