📜  arrondi js - Javascript (1)

📅  最后修改于: 2023-12-03 15:13:30.004000             🧑  作者: Mango

Arrondi JS - Javascript

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.

Features
  • Option to round up or down
  • Option to round to the nearest value
  • Specify the number of decimal places to round to
  • Supports positive and negative numbers
  • Lightweight and easy to use
  • Open-source
Getting Started

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
Examples

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
Contributing

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.

License

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.