Get the App
SLTechnology News&Howtos  ›  Development  › 

How to take the last two decimal places in jquery by division

Shulou Source: shulou.com Published: 2022-06-02 02:34:23 10月02日 Update

This article mainly explains the "jquery division how to take the decimal places", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "jquery division how to take the decimal places" bar!

Methods: 1, use the toFixed () method to take two decimal places, this method can be rounded to the specified decimal places, the syntax is "division result .tofixed (2)"; 2, the use of round () method to take the last two decimal places, the syntax is "Math.round (division result * 100) / 100".

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to take the last two decimal places in jquery by division

1. The toFixed () method rounds Number to a specified number of decimal places.

Grammar

NumberObject.toFixed (num)

Num is required. The specified number of decimal places is a value between 0 and 20, including 0 and 20, and some implementations can support a wider range of values. If this parameter is omitted, 0 will be used instead.

Return value

Returns the string representation of NumberObject, instead of exponential counting, with fixed num digits after the decimal point. If necessary, the number is rounded, or it can be filled with 0 so that it reaches the specified length. If num is greater than le+21, the method simply calls NumberObject.toString () and returns the string represented by exponential counting.

Examples are as follows:

Var x = 7 demo var y = 8 politic var z = x / y politic var result = z.toFixed (2); document.getElementById ("demo") [xss_clean] = result

Output result:

2. The round () method rounds a number to the nearest integer.

Grammar

Math.round (x)

X required. It has to be a number.

Return value

The integer closest to x.

Description

For 0.5, this method rounds up.

For example, 3.5 will be rounded to 4 and-3.5 will be rounded to-3.

Examples are as follows:

Var x = 7 position var y = 8 xss_clean z = x / y politics var result = Math.round (Zhen100) / 100 scape document.getElementById ("demo") [xss_clean] = result

Output result:

Thank you for your reading, the above is the content of "how to take the last two decimal places in jquery division". After the study of this article, I believe you have a deeper understanding of how division in jquery takes the last two decimal places, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Decimal points methods division numbers results grammar learning rounding digits content characters strings exponents integers examples rounding counting output necessary Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information NVidia Shulou Tech Info Linux