JSR

Parses a string as an xsd:decimal lexical form and returns it as a branded Decimal.

This function validates the input against the XML Schema xsd:decimal lexical space after applying the XML Schema whiteSpace="collapse" normalization step. It returns the normalized string without any further canonicalization.

Examples

Example 1

const price = parseDecimal("12.50");

Example 2

const price = parseDecimal(" 12.50 ");
console.assert(price === "12.50");

Example 3

try {
  parseDecimal("1e3");
} catch (error) {
  console.assert(error instanceof TypeError);
}

Parameters

A candidate xsd:decimal lexical form.

Return Type

The normalized string branded as Decimal.

Throws

Thrown when the value is not a valid xsd:decimal lexical form.

Read the original on jsr.io ↗