# 推荐一个货币计算&格式换的轻量级类库，耐心看后面的小技巧哈

{% embed url="<https://v.douyin.com/r8yQ5s2/>" %}

{% embed url="<https://www.bilibili.com/video/BV1eG4y1q7qX/>" %}

大家项目里如果涉及到这种金额呀

或者价格

这种货币类型的数据比较多的话

给大家推荐一下这个类库哈

特别轻量级才1.14 k

它核心的两个功能一个是计算

一个是格式化

我先给大家演示一下计算

首先我这里有一串数字

正常如果我累加0.

加着加着就容易出现这种精度问题

然后给他换成他这种计算方法呢 大家看

我们再来试一下

打开就没问题了

然后关于格式化呢

正常的话

我们直接在他结果上直接点否卖

他就可以了哈

那我在这里给大家推荐一个小技巧啊

我们可以在全局把它引进来

然后呢放到这个vue.prototype里边

然后后边指定一下这个人民币的货币

符号

然后我们就可以在

前面 在这直接用 currency(xxx)

然后呢把它扩上

点

如果不需要计算直接format就行了

如果需要计算

可以直接在这进行 .add 呀

或者什么操作就行了

我直接format大家看

这样就好了

那还可以更简单一点

比如说我们大部分情况都不需要计算

就是想格式化一下

那就可以在这

这样再封装一个format money

然后把这个再封装一层

这样的话呢

我们就可以在页面上直接这么调了

直接这样然后把这个format去掉

我们再来试一下

大家看！就没问题了


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sunzsh.gitbook.io/xiaoshan.bug/tui-jian-yi-ge-huo-bi-ji-suan-ge-shi-huan-de-qing-liang-ji-lei-ku-nai-xin-kan-hou-mian-de-xiao-ji-qi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
