Číslo Javascript toLocaleString ()

Metoda JavaScript Number toLocaleString () vrací řetězec s jazykově citlivou reprezentací tohoto čísla.

Syntaxe toLocaleString()metody je:

 num.toLocaleString(locales, options)

Tady numje číslo.

toLocaleString () parametry

toLocaleString()Metoda bere v:

  • locales (Optional) - Řetězec určující, který jazyk specifický formát použít.
  • options (Volitelné) - Objekt s vlastnostmi konfigurace.

Další informace najdete v konstruktoru Intl.NumberFormat ().

Vrátit hodnotu z toLocaleString ()

  • Vrátí řetězec s jazykově citlivou reprezentací daného čísla.

Příklad: Použití metody toLocaleString ()

 let number = 400000; console.log(number.toLocaleString()); // 400,000 if in US English locale // using locales let number1 = 123456.789; // India uses thousands/lakh/crore separators console.log(number1.toLocaleString("en-IN")); // 1,23,456.789 // using options let currency = number1.toLocaleString("de-DE", ( style: "currency", currency: "EUR", maximumSignificantDigits: 3, )); console.log(currency); // 123.000 €

Výstup

 400 000 1 23 456 789 123 000 EUR

Doporučená literatura:

  • Číslo Javascript toString ()

Zajímavé články...