@valeera/mathx
Version:
A math library written in TS.
13 lines (12 loc) • 355 B
text/typescript
/**
* @function floorToZero
* @desc 以0为中心取整
* @param {number} num 数值
* @return {number} 取整之后的结果
* @example Mathx.roundToZero(0.8 ); // 0;
* Mathx.roundToZero(-0.8); // 0;
* Mathx.roundToZero(-1.1); // -1;
*/
export const floorToZero = (num: number): number => {
return num < 0 ? Math.ceil(num) : Math.floor(num);
};