feat(numberToCurrency): 货币符号写死
This commit is contained in:
parent
e6c9573fdb
commit
92bc66d9d6
|
@ -1,30 +1,34 @@
|
||||||
import store from '@/store'
|
|
||||||
let userInfo = uni.getStorageSync('User')
|
let userInfo = uni.getStorageSync('User')
|
||||||
export function stateFormat(row, column, cellValue) {
|
export function stateFormat(row, column, cellValue) {
|
||||||
if (cellValue) {
|
if (cellValue) {
|
||||||
return Number(cellValue)
|
return Number(cellValue)
|
||||||
.toFixed(2)
|
.toFixed(2)
|
||||||
.replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
|
.replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
|
||||||
|
return $1 + ','
|
||||||
return $1 + ',';
|
|
||||||
})
|
})
|
||||||
|
|
||||||
.replace(/\.$/, "");
|
.replace(/\.$/, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//element 转成千分位并保留小数
|
//element 转成千分位并保留小数
|
||||||
//decimal 默认保留2位小数
|
//decimal 默认保留2位小数
|
||||||
export function toThousandthAndKeepDecimal(element, decimal = 2) {
|
export function toThousandthAndKeepDecimal(element, decimal = 2) {
|
||||||
if (!element || element === '') {//值不存在 或为空
|
if (!element || element === '') {
|
||||||
|
//值不存在 或为空
|
||||||
return ''
|
return ''
|
||||||
} else if (typeof element == 'string') {
|
} else if (typeof element == 'string') {
|
||||||
return Number(element).toLocaleString(undefined, { minimumFractionDigits: decimal, maximumFractionDigits: decimal });
|
return Number(element).toLocaleString(undefined, {
|
||||||
|
minimumFractionDigits: decimal,
|
||||||
|
maximumFractionDigits: decimal,
|
||||||
|
})
|
||||||
} else if (typeof element == 'number') {
|
} else if (typeof element == 'number') {
|
||||||
return element.toLocaleString(undefined, { minimumFractionDigits: decimal, maximumFractionDigits: decimal });
|
return element.toLocaleString(undefined, {
|
||||||
|
minimumFractionDigits: decimal,
|
||||||
|
maximumFractionDigits: decimal,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
return element;
|
return element
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// 千分号
|
// 千分号
|
||||||
export function numberToCurrencyNo(value) {
|
export function numberToCurrencyNo(value) {
|
||||||
|
@ -36,14 +40,17 @@ export function numberToCurrencyNo(value) {
|
||||||
// 获取整数部分
|
// 获取整数部分
|
||||||
const intPart = Math.trunc(value)
|
const intPart = Math.trunc(value)
|
||||||
// 整数部分处理,增加,
|
// 整数部分处理,增加,
|
||||||
const intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
|
const intPartFormat = intPart
|
||||||
|
.toString()
|
||||||
|
.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
|
||||||
// 预定义小数部分
|
// 预定义小数部分
|
||||||
let floatPart = ''
|
let floatPart = ''
|
||||||
// 将数值截取为小数部分和整数部分
|
// 将数值截取为小数部分和整数部分
|
||||||
const valueArray = value.toString().split('.')
|
const valueArray = value.toString().split('.')
|
||||||
if (valueArray.length === 2) { // 有小数部分
|
if (valueArray.length === 2) {
|
||||||
|
// 有小数部分
|
||||||
floatPart = valueArray[1].toString() // 取得小数部分
|
floatPart = valueArray[1].toString() // 取得小数部分
|
||||||
if(floatPart.length == 1){
|
if (floatPart.length == 1) {
|
||||||
floatPart = floatPart + '0'
|
floatPart = floatPart + '0'
|
||||||
}
|
}
|
||||||
return intPartFormat + '.' + floatPart
|
return intPartFormat + '.' + floatPart
|
||||||
|
@ -62,9 +69,9 @@ export function numberToCurrencyNo(value) {
|
||||||
// }
|
// }
|
||||||
// 添加当地币
|
// 添加当地币
|
||||||
export function isLocal(value) {
|
export function isLocal(value) {
|
||||||
return (store.getters.user.currencyIcon + value) || (userInfo.currencyIcon + value)
|
return '¥' + value
|
||||||
}
|
}
|
||||||
// 添加当地币
|
// 添加当地币
|
||||||
export function isLocaled(value) {
|
export function isLocaled(value) {
|
||||||
return store.getters.user.currencyIcon || userInfo.currencyIcon
|
return '¥'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue