Lodash.js测试,数学(Math)方法的扩展

版权声明:本文为个人知识整理,欢迎指正、交流、转载。 https://blog.csdn.net/u014711094/article/details/83273166
  • round ceil floor
let num = 555.555

_.round(num)		// 556
_.round(num, 1)		// 555.6
_.round(num, -1)	// 560

// 和round用法相似
_.ceil(num, -1)		// 560
_.floor(num, -1)	// 550

// 参数为string
_.round('555.555')		// 556, 会先toNumber

// 参数为负数
_.round(-555.555)		// -556, the nearest number
_.ceil(-555.555)		// -555, the smallest number greater than or equal to 
_.floor(-555.555)		// -556, the greatest number smaller than or equal to

// todo: 实现myRound(n, precision)

猜你喜欢

转载自blog.csdn.net/u014711094/article/details/83273166
今日推荐