Skip to content

Amount 金额

基础用法

  • 用于格式化展示金额,将数值拆分为货币符号、整数、小数三部分渲染,可分别控制字号与颜色。
  • value 支持 Number 或字符串;字符串可自带货币符号与千分位分隔符(如 '¥888,888.88'),内部自动解析。
  • 舍入基于字符串精确计算(不经过浮点 toFixed),提供 round / ceil / floor / trunc 四种模式,避免浮点精度误差。
  • 支持中文大写金额(to-upper,符合央行票据规范)、千分位分隔、语义配色、可选中复制等能力。
vue
<template>
	<sn-amount :value="123456.789" currency="¥"></sn-amount>
</template>

更多演示请下载 demo 查看

舍入模式与小数位

rounding-mode 四种规则:round 四舍五入、ceil 进一法(向正无穷)、floor 退一法(向负无穷)、trunc 截断法(向零);decimals 控制保留位数,不足自动补 0。

vue
<template>
	<sn-amount :value="'1.005'" currency="¥" :decimals="2" rounding-mode="round"></sn-amount>
	<sn-amount :value="'-1.005'" currency="¥" :decimals="2" rounding-mode="ceil"></sn-amount>
	<sn-amount :value="'1234.56789'" currency="$" :decimals="4"></sn-amount>
</template>

中文大写金额

to-upper 显示中文大写金额,支持负数与万亿级数值;此时可配合 typebold 等统一控制样式。

vue
<template>
	<sn-amount :value="12345.67" :to-upper="true" type="primary"></sn-amount>
	<sn-amount :value="'-12345678901234.56'" :decimals="2" :to-upper="true"></sn-amount>
</template>

分部分样式

currency-font-size / int-font-size / decimal-font-sizecurrency-color / int-color / decimal-color 分别控制三部分字号与颜色(优先于 font-size / color),也可用对应的外部样式类定制。

vue
<template>
	<sn-amount :value="'88888.66'" currency="¥"
		currency-font-size="14px" currency-color="$textLight"
		int-font-size="28px" int-color="$primary"
		decimal-font-size="14px" decimal-color="$textLight" bold></sn-amount>
</template>

属性

参数说明类型默认值可选值
value金额值,支持 Number 或字符串(字符串可含货币符号、千分位分隔符,解析时自动去除)String | Number0-
currency货币符号,为空时不显示String''-
decimals保留小数位数,0 表示不显示小数部分Number2-
rounding-mode舍入模式Stringroundround | ceil | floor | trunc
separator整数千分位分隔符,传空字符串不分割String,-
separator-digits千分位分隔位数Number3-
to-upper是否显示中文大写金额Booleanfalsetrue | false
type语义配色类型(与 sn-text 一致),可被 color 覆盖Stringtexttitle | text | text-light | primary | info | success | warning | error
font-size统一字号,支持 $ 前缀动态尺寸;为空时默认 14px × fontsizeFactor(title 为 16px × fontsizeFactor)String | Number''-
currency-font-size货币符号字号,优先于 font-sizeString | Number''-
int-font-size整数部分字号,优先于 font-sizeString | Number''-
decimal-font-size小数部分(含小数点)字号,优先于 font-sizeString | Number''-
color统一文字颜色,支持 $ 简写String''-
currency-color货币符号颜色,优先于 colorString''-
int-color整数部分颜色,优先于 colorString''-
decimal-color小数部分颜色,优先于 colorString''-
bold是否加粗(字重 600)Booleanfalsetrue | false
lines最大行数,0 表示不限制,超出部分省略Number0-
selectable是否可长按选中复制Booleanfalsetrue | false
currency-style货币符号外部样式UTSJSONObject | String''-
currency-class货币符号外部样式类String''-
int-style整数部分外部样式UTSJSONObject | String''-
int-class整数部分外部样式类String''-
decimal-style小数部分外部样式UTSJSONObject | String''-
decimal-class小数部分外部样式类String''-
text-class大写金额文本外部样式类(to-upper 为 true 时作用)String''-
custom-style自定义根节点样式UTSJSONObject | String''-
custom-class根节点外部样式类String''-

使用 MIT 协议