Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 4x 4x 4x 4x 26x 26x 26x 26x 26x 26x 26x 22x 4x 4x | import Big from 'big.js';
import * as R from 'ramda';
import { formatDecimalNoRound } from './formatDecimalNoRound';
import { RestParams } from './interface';
/**
* 大数字转小数字
* @param translateUnit
*/
export const bigToSmall = (translateUnit: number) => {
return (num: number | string, params?: RestParams) => {
const decimalNumber = params?.decimalNumber || 2;
const fn = params?.fn || 'toFixed';
Iif (R.isEmpty(num) || R.isNil(num)) return num;
Iif (isNaN(Number(num))) {
return NaN;
}
const newNumber = new Big(Number(num)).div(translateUnit);
if (fn === 'toFixed') {
return Number(newNumber.toFixed(decimalNumber));
} else Eif (fn === 'floor') {
return formatDecimalNoRound(Number(newNumber), decimalNumber);
}
return num;
}
} |