Home > Web Front-end > JS Tutorial > Introduction to the example method of implementing decimal rounding in js

Introduction to the example method of implementing decimal rounding in js

零下一度
Release: 2017-06-15 13:31:54
Original
1254 people have browsed it

This article mainly introduces the implementation of a very simple decimal rounding function in javascript, and analyzes the related operation skills of javascript mathematical operation rounding in the form of specific examples. Friends in need can refer to the following

The examples in this article describe JavaScript implements a very simple decimal rounding function. Share it with everyone for your reference, the details are as follows:

JS core code:


function truncateNumber(n){
  return n|0;
}
Copy after login

Usage example:


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JS小数取整</title>
</head>
<body>
<script >
function truncateNumber(n){
return n|0;
}
console.log(truncateNumber(12.345));
</script>
</body>
</html>
Copy after login

The operation effect diagram is as follows:

The above is the detailed content of Introduction to the example method of implementing decimal rounding in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template