Home  >  Article  >  Web Front-end  >  Simple sample code for implementing decimal rounding function in JavaScript

Simple sample code for implementing decimal rounding function in JavaScript

黄舟
黄舟Original
2017-06-18 13:09:361042browse

This article mainly introducesjavascript to implement a very simple decimal rounding function, and analyzes the related operation skills of JavaScript mathematical operations rounding based on specific examples. Friends who need it can For reference,

The example in this article describes how to implement a very simple decimal rounding function in javascript. Share it with everyone for your reference, the details are as follows:

JS core code:


function truncateNumber(n){
  return n|0;
}

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>

The operation effect diagram is as follows:

The above is the detailed content of Simple sample code for implementing decimal rounding function 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