Get the App
SLTechnology News&Howtos  ›  Development  › 

How does javascript convert a number into a string

Shulou Source: shulou.com Published: 2022-06-02 22:59:44 10月16日 Update

This article introduces the relevant knowledge of "how javascript converts numbers into strings". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Javascript will be a number into a string of methods: 1, the number and empty string addition operation, the syntax "num +"; 2, the use of toString () method, syntax "num.toString ()"; 3, the use of toFixed () method, syntax "num.toFixed ()".

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

Javascript converts numbers to strings

1. Use the plus operator

When a number is added to an empty string, JavaScript automatically converts the value to a string.

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

2. Use the toString () method

Var n = 123 n = n.toString (); console.log (typeof n)

3. Use the toFixed () method

Var n = 123.21 * * n = n.toFixed (); console.log (typeof n)

This is the end of "how javascript converts numbers into strings". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Numbers characters strings methods grammar operations content more knowledge empty characters practicality learning next plus sign dilemma reality situation tutorials articles cases Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS MariaDB Linux Shulou Information