Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert a number into a string in javascript

Shulou Source: shulou.com Published: 2022-06-03 15:48:57 09月29日 Update

This article introduces how to convert numbers into strings in javascript. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

1. Use the plus sign "+" operator and the syntax "number +".

Var n = 123 typeof n = n + "; console.log (typeof n); / / return type is string

2. Use toString () method, syntax "numeric variable .toString ()".

Var a = 1.000 console.log var b = 0.0001 console.log var c = 1e Mui 1x console.log (b.toString ()); / / returns the string "1" (c.toString ()); / / returns the string "0.0001" (c.toString ()); / / returns the string "0.0001"

3. Convert a number to a decimal format string with toFixed (), toExponential (), or toPrecision ().

Var a = 10 position console.log (a.toFixed (2)); / / return the string "10.00" console.log (a.toFixed (4)); / / return the string "10.0000" about how to convert numbers into strings in javascript and that's it. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.

Tags: Characters strings numbers content more grammar help good interest plus sign variables boys buddies decimals articles methods formats knowledge articles types Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS Shulou Tech Info Microsoft Redmi