Get the App
SLTechnology News&Howtos  ›  Development  › 

How does javascript get rid of the remainder

Shulou Source: shulou.com Published: 2022-06-01 13:16:38 10月05日 Update

This article mainly shows you "javascript how to remove the remainder", the content is simple and easy to understand, clear organization, I hope to help you solve doubts, let Xiaobian lead you to study and learn "javascript how to remove the remainder" this article bar.

In JavaScript, removing the remainder, i.e., the decimal point, can be done using the parseInt() function, which parses a string and returns an integer with the syntax "parseInt(division result)."

Operating environment of this tutorial: Windows 10 system, Javascript version 1.8.5, Dell G3 computer.

Javascript how to remove the remainder

parseInt() parses a string and returns an integer.

When radix is 0 or not set, parseInt() determines the radix of the number based on string.

When ignoring the radix parameter, JavaScript defaults to the following radix:

If the string starts with "0x," parseInt() resolves the rest of the string to hexadecimal integers.

If string starts with 0, ECMAScript v3 allows an implementation of parseInt() to parse the following characters into octal or hexadecimal digits.

If string starts with a number from 1 to 9, parseInt() will parse it to a decimal integer.

syntax

parseInt(string, radix)

parameter description

string Required. The string to be parsed.

The radix is optional. Represents the radix of the number to parse. This value ranges from 2 to 36.

Examples are as follows:

123var y = 5;var z = 2;var b = 3;var x = y / z;var c = y / b;[xss_clean](parseInt(x) + "

") ;[xss_clean](parseInt(c) + "

");

Output:

The above is "javascript how to remove the remainder" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Remainder number parameter character integer content function cardinality string beginning article hexadecimal result grammar learning help in between that is octal decimal Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Huawei Xiaomi NVidia vpn