

GitHub - nick-lai/round-decimal: Decimal rounding with ULP.
source link: https://github.com/nick-lai/round-decimal
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

round-decimal
Decimal rounding with ULP.
Warning
Work in process
Installation
npm install -D round-decimal
jsDelivr
Load roundDecimal
from jsDelivr.
<script src="https://cdn.jsdelivr.net/npm/round-decimal"></script>
unpkg
Load roundDecimal
from unpkg.
<script src="https://unpkg.com/round-decimal"></script>
Usage
Syntax
roundDecimal(value, minSignificantFractionDigits = 3)
Description
Decimal rounding with ULP.
Parameters
value
- A number.
minSignificantFractionDigits
- Minimum significant fraction digits.
- Default:
3
Return value
The rounded value.
Examples
import roundDecimal from 'round-decimal';
console.log(0.1 + 0.2); // 0.30000000000000004
console.log(roundDecimal(0.1 + 0.2)); // 0.3
console.log(-0.1 - 0.2); // -0.30000000000000004
console.log(roundDecimal(-0.1 - 0.2)); // -0.3
console.log(10000000000.1 + 10000000000.2); // 20000000000.300003
console.log(roundDecimal(10000000000.1 + 10000000000.2)); // 20000000000.3
console.log(roundDecimal(10000000000.1 + 10000000000.2, 6)); // 20000000000.300003
console.log(10000000000000.1 + 10000000000000.2); // 20000000000000.297
console.log(roundDecimal(10000000000000.1 + 10000000000000.2)); // 20000000000000.297
console.log(roundDecimal(10000000000000.1 + 10000000000000.2, 2)); // 20000000000000.3
console.log(roundDecimal(1.3549999999999998)); // 1.355
Try it out on JSFiddle.
License
Recommend
-
29
README.md Squircle
-
34
Join GitHub today GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
-
10
Round float to 2 decimal places yourbasic.org/golang Float to string To display the value as a string, use the fmt.Sprintf method.
-
8
Richard Lai, Senior Editor; Engadget Chinese Editor in Chief
-
15
SQL Server Rounding Functions - Round, Ceiling and Floor By: Jeremy Kadlec | Updated: 2021-07-20 |
-
7
Rounding in Java – Math.Round, Math.Floor, Math.CeilWe have decimal values in java, but sometimes there is a need to round them. It is important to remember which function should be used according to the requirements. So In...
-
8
Xiao Zhao June 8, 2022 2 minute read
-
7
1. LAI简介1.1. LAI 关于重复序列和LTR的相关知识可以参考博客:基因组注释(一):重复序列注释:...
-
14
August 22, 2022 /
-
5
PHP RFC: Add 4 new rounding modes to round() function ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK