Home  >  Article  >  Web Front-end  >  What are the data type conversion functions in JavaScript?

What are the data type conversion functions in JavaScript?

青灯夜游
青灯夜游Original
2021-11-19 17:07:573117browse

Data type conversion functions include: toExponential(), toFixed(), toPrecision(), String(), getDate(), getFullYear(), Number(), parseFloat(), parseInt(), etc.

What are the data type conversion functions in JavaScript?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Data type conversion in JavaScript

1. Convert numbers to strings

  • toExponential() Convert the value of the object to exponential notation.

  • toFixed() Converts a number to a string. The result has the specified number of digits after the decimal point.

  • toPrecision() Format the number to the specified length.

2. Convert Boolean value to string

String(): You can convert Boolean value to string

3. Convert the date to a string

  • Date() returns a string representing the date

  • String( ) You can convert the date object into a string

  • getDate() returns the day of the month (1 ~ 31) from the Date object.

  • getDay() Returns the day of the week (0 ~ 6) from the Date object.

  • getFullYear() Returns the year as a four-digit number from a Date object.

  • getHours() Returns the hours (0 ~ 23) of the Date object.

  • getMilliseconds() returns the milliseconds (0 ~ 999) of the Date object.

  • getMinutes() Returns the minutes (0 ~ 59) of the Date object.

  • getMonth() Returns the month (0 ~ 11) from the Date object.

  • getSeconds() Returns the number of seconds (0 ~ 59) of the Date object.

  • getTime() Returns the number of milliseconds since January 1, 1970.

4. Convert strings to numbers

  • Number(): You can convert strings to numbers

  • parseFloat() Parses a string and returns a floating point number.

  • parseInt() Parses a string and returns an integer.

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of What are the data type conversion functions in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn