통화 포맷(필터)
코드
// (github: vuex --> demo --> shopping-cart -->currency.js)
const digitsRE = /(\d{3})(?=\d)/g
// value: ; currency: ; decimals ;
export function currency (value, currency, decimals) {
value = parseFloat(value)
if (!isFinite(value) || (!value && value !== 0)) return ''
currency = currency != null ? currency : '$'
decimals = decimals != null ? decimals : 2
var stringified = Math.abs(value).toFixed(decimals)
var _int = decimals
? stringified.slice(0, -1 - decimals)
: stringified
var i = _int.length % 3
var head = i > 0
? (_int.slice(0, i) + (_int.length > 3 ? ',' : ''))
: ''
var _float = decimals
? stringified.slice(-1 - decimals)
: ''
var sign = value < 0 ? '-' : ''
return sign + currency + head +
_int.slice(i).replace(digitsRE, '$1,') +
_float
}
사용법
1, vue
// (main.js)
import {
currency} from './util/currency'
Vue.filter("currency",currency);
// ( )
<div class="item-price">{
{
item.salePrice | currency('$')}}</div>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
조건자로 필터링프로그래밍에서 컬렉션이 있을 때 요구 사항을 충족하는 부분을 필터링하고 나머지는 버려야 하는 경우가 있습니다. 자세한 예는 환자 기록 목록이 있고 미성년 환자 목록을 가져오려는 경우입니다. 이 코드를 자바 파일에 복...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.