/**
* 根据precision(精度)向上舍入number。(precision(精度)可以理解为保留几位小数)
* Computes `number` rounded up to `precision`
* @param {number} number The number to round up
* @param {number} [precision=0] The precision to round up to
* @returns {number} Returns the rounded up number
* @example
* ceil(4.006)
* // => 5
* ceil(6.004, 2)
* // => 6.01
*/
import createRound from "../utils/createRound"
var ceil = createRound("ceil")
export default ceil
/**
* Creates a function like `round`
* @param {string} methodName The name of the `Math` method to use when rounding
* @returns {Function} Returns the new round function
*/
import toNumber from "./toNumber" //在我的博客中搜索【转换为数字】
import toInteger from "./toInteger" //在我的博客中搜索【转换为整数】
function createRound(methodName) {
var func = Math[methodName]
return function(number, precision) {
number = toNumber(number)
precision = precision == null ? 0 : Math.min(toInteger(precision), 292)
if (precision) {
// Shift with exponential notation to avoid floating-point issues.
// See [MDN](https://mdn.io/round#Examples) for more details.
var pair = (String(number) + "e").split("e"),
value = func(pair[0] + "e" + (+pair[1] + precision))
pair = (String(value) + "e").split("e")
return +(pair[0] + "e" + (+pair[1] - precision))
}
return func(number)
}
}
export default createRound