Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the data type conversion functions in JavaScript

Shulou Source: shulou.com Published: 2022-06-02 13:01:36 09月22日 Update

This article is about what data type conversion functions are available in JavaScript. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The data type conversion functions are: toExponential (), toFixed (), toPrecision (), String (), getDate (), getFullYear (), Number (), parseFloat (), parseInt (), and so on.

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

Data type conversion in JavaScript

1. Convert numbers to strings

ToExponential () converts the value of the object to an exponential counting method.

ToFixed () converts a number to a string with a specified number of digits after the decimal point of the result.

ToPrecision () formats the number to the specified length.

2. Convert a Boolean value to a string

String (): Boolean values can be converted to strings

3. Convert the date to a string

Date () returns a string representing the date

String () can convert a date object to 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 in four digits from the Date object.

GetHours () returns the hours of the Date object (0-23).

GetMilliseconds () returns the milliseconds (0-999) of the Date object.

GetMinutes () returns the minutes of the Date object (0-59).

GetMonth () returns the month (0-11) from the Date object.

GetSeconds () returns the number of seconds of the Date object (0-59).

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.

Thank you for reading! This is the end of this article on "what data type conversion function in JavaScript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Characters strings objects numbers data types functions dates content Boolean more articles good practical digits decimal decimal hour year index Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Shulou Tech Info Docker Linux