非四舍五入
getKeepTwoDecimals(val) {
? ? ? ? ? ? ? ? if(val){
? ? ? ? ? ? ? ? ? ? ? ? var newVal = (parseInt(val * 100) / 100).toFixed(2);
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? var newVal="0.00"
? ? ? ? ? ? ? ? }
? ? ? ? ? ? return newVal;
? ? ? ? ? ? },
四舍五入
?* @param {Number} position 要保留的位數(shù)
?* @param {Number or String} number 傳入的數(shù)字
?*/
export function formatNumber(position, number){
? ? if(!number){
? ? return '0.00'
? ? }
? ? const positionNumber = Math.pow(10, position)
? ? const result = Math.round( parseFloat(number) * positionNumber ) / positionNumber;
? ? return result.toFixed(position)
}