# round-to **Repository Path**: ArkTSCentralRepository/round-to ## Basic Information - **Project Name**: round-to - **Description**: round-to 是一个库,用于将数字舍入到指定的小数位数,支持常规舍入、向上舍入和向下舍入操作。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-21 - **Last Updated**: 2024-11-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # round-to 基于[round-to](https://www.npmjs.com/package/round-to)原库6.0.0版本进行适配, 所有功能代码已经转换为`ArkTS`文件 ## Install ```sh ohpm install round-to ``` ## Description > Round a number to a specific number of decimal places: `1.234` → `1.2` ## Usage ```typescript import {roundTo, roundToUp, roundToDown} from 'round-to'; roundTo(1.234, 2); //=> 1.23 roundToUp(1.234, 2); //=> 1.24 roundToDown(1.234, 2); //=> 1.23 ``` Numbers are rounded to a specific number of fractional digits. Specifying a negative `precision` will round to any number of places to the left of the decimal. ```typescript roundTo(1234.56, -2); //=> 1200 ``` Specifying an infinite `precision` will assume infinite decimal places. ```typescript roundTo(0.1231782638, Infinity); //=> 0.1231782638 ``` ## API ### roundTo(number, precision) Round the decimals with [`Math.round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round). ### roundToUp(number, precision) Round up the decimals with [`Math.ceil`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil). ### roundToDown(number, precision) Round down the decimals with [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor). #### number Type: `number` The number to adjust. #### precision Type: `number` *(Integer or infinity)* The number of decimal places.