📅  最后修改于: 2023-12-03 15:13:30.004000             🧑  作者: Mango
Arrondi JS is a lightweight, open-source Javascript library for rounding numbers to a specified number of decimal places. With just a few lines of code, you can easily round numbers up, down, or to the nearest value.
To get started using Arrondi JS, you can include it in your HTML file with a script tag:
<script src="arrondi.js"></script>
Once you have included the script, you can start using it in your Javascript code. Here are a few examples:
// Rounding up to two decimal places
var myNumber = 3.14159;
var roundedNumber = arrondi.up(myNumber, 2);
// Result: 3.15
// Rounding down to one decimal place
var myNumber = 9.87654;
var roundedNumber = arrondi.down(myNumber, 1);
// Result: 9.8
// Rounding to the nearest integer
var myNumber = 3.6;
var roundedNumber = arrondi.nearest(myNumber, 0);
// Result: 4
Here are a few more examples of using Arrondi JS:
// Rounding up to three decimal places
var myNumber = -1.2345;
var roundedNumber = arrondi.up(myNumber, 3);
// Result: -1.234
// Rounding down to five decimal places
var myNumber = 0.987654321;
var roundedNumber = arrondi.down(myNumber, 5);
// Result: 0.98765
// Rounding to the nearest 0.25
var myNumber = 2.8;
var roundedNumber = arrondi.nearest(myNumber, 0.25);
// Result: 2.75
If you would like to contribute to Arrondi JS, you can fork the repository on GitHub and submit a pull request. We welcome contributions of any kind, whether it's bug fixes, new features, or documentation improvements.
Arrondi JS is released under the MIT license. You are free to use, modify, distribute, and sell it however you like, with or without attribution.