1. 程式人生 > >Lodash.js測試,數學(Math)方法的擴充套件

Lodash.js測試,數學(Math)方法的擴充套件

  • 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)