Skip to content

WD JS Number Tools

wdonadelli edited this page Nov 12, 2022 · 17 revisions

WD JS Number Tools

When informed factorial or percentage values (Strings), the corresponding mathematical value will be assigned, that is, 10% will be transformed to 0.1 and 3! will be transformed to 6.

The initial value cannot be modified by methods or attributes.

To find the description of the tools presented in this section, it is recommended that you read the following topics:

abs

wd(number).abs
let a = wd(2048.58);
a.abs; /* returns 2048.58 */
let b = wd("-10%");
b.abs; /* returns 0.1 */

byte

wd(number).byte
let a = wd(2048.58);
a.byte; /* returns "2.00kB" */

dec

wd(number).dec
let a = wd(2048.58);
a.dec; /* returns 0.58 */

fixed

wd(number).fixed(ldec, lint)
Argument Type Mandatory Description
ldec Integer No Number of decimal places to display. (default value 0)
lint Integer No The minimum number of integer characters. (default value 0)
let p = wd(3.456);
p.fixed();    /* returns "3" */
p.fixed(2);   /* returns "3.46" */
p.fixed(2,2); /* returns "03.46" */
p.fixed(5,3); /* returns "003.45600" */

frac

wd(number).frac
let a = wd(2048.58);
a.frac; /* returns "2048 29/50" */

int

wd(number).int
let a = wd(2048.58);
a.int;   /* returns 2048 */

locale

wd(number).locale(currency)
Argument Type Mandatory Description
currency String No Defines the currency code (ISO 4217).

If a suitable value for the "currency" argument is given, it will return a monetary value.

let p = wd(1050.456);
/* if wd.lang == "pt-BR": */
p.locale();      /* returns "1.050,456" */
p.locale("BRL"); /* returns "R$ 1.050,46" */
p.locale("USD"); /* returns "US$ 1.050,46" */
/* if wd.lang == "en-US": */
p.locale();      /* returns "1,050.456" */
p.locale("BRL"); /* returns "R$1,050.46" */
p.locale("USD"); /* returns "$1,050.46" */

ntype

wd(number).ntype

Possible values for ntype are (strings):

Value Example
zero 0
+infinity Infinity
-infinity -Infinity
+integer 3
-integer -3
+float 0.3
-float -0.3
let a = wd(2048.58);
a.ntype; /* returns "+real" */

pow10

wd(number).pow10(width)
Argument Type Mandatory Description
width Number No Number of decimal places to display.
let p = wd(3.456);
p.pow10();  /* returns "3.456 x 10⁺⁰" */
p.pow10(2); /* returns "3.46 x 10⁺⁰" */

round

wd(number).round(width);
Argument Type Mandatory Description
width Number No Number of decimal places to round (default value 0).
let p = wd(3.456);
p.round();  /* returns 3 */
p.round(2); /* returns 3.46 */

str

wd(number).str
let a = wd(2048.58);
a.str; /* returns "2.0e+3" */
let b = wd("-10%");
b.str; /* returns "-0.10" */

test

See test method.

Clone this wiki locally