jquery精度计算代码 jquery指定精确小数位
作者:追逐繁星 时间:2024-05-21 10:20:21
本文实例为大家分享了jquery指定精确小数位的具体代码,供大家参考,具体内容如下
/**
* 将标签的值格式化
* id 标签id
* min 最小值
* max 最大值
*/
function toFloat(id,min,max){
var htmlVal = $("#"+id).html();
var index = htmlVal.indexOf(".");
var result = "";
if(index > 0){
htmlVal = htmlVal.replaceAll("0+?$","");
var len = htmlVal.substring(index+1).length;
if(len > min){
if(len > max){
result = Number(htmlVal).toFixed(max);
result = result.replaceAll("0+?$","");
}else{
result = Number(htmlVal).toFixed(len);
result = result.replaceAll("0+?$","");
}
}else {
result = Number(htmlVal).toFixed(min);
}
}else {
result = Number(htmlVal).toFixed(min);
}
$("#"+id).html(result);
}
页面显示:
标签:jquery,精度计算,小数位
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现提取音乐频谱的方法详解
2022-01-27 07:03:08
![](https://img.aspxhome.com/file/2023/2/72072_0s.jpg)
Access函数大全
2009-12-23 19:22:00
pytorch绘制曲线的方法
2022-09-03 06:43:54
![](https://img.aspxhome.com/file/2023/7/112477_0s.jpg)
详解Python之Scrapy爬虫教程NBA球员数据存放到Mysql数据库
2024-01-24 03:27:04
![](https://img.aspxhome.com/file/2023/2/79702_0s.jpg)
Python OpenCV特征检测之特征匹配方式详解
2021-07-20 00:51:58
![](https://img.aspxhome.com/file/2023/0/77580_0s.jpg)
基于SQLAlchemy实现操作MySQL并执行原生sql语句
2024-01-18 17:16:05
Go语言读写锁RWMutex的源码分析
2024-05-09 09:47:55
![](https://img.aspxhome.com/file/2023/1/127331_0s.jpg)
pymssql ntext字段调用问题解决方法
2022-04-22 06:55:06
Django框架模板介绍
2021-07-05 07:34:18
Pandas之缺失数据的实现
2022-05-04 19:00:05
![](https://img.aspxhome.com/file/2023/9/115099_0s.png)
Python可视化Matplotlib介绍和简单图形的绘制
2021-09-01 21:16:44
![](https://img.aspxhome.com/file/2023/8/109508_0s.jpg)
细数nn.BCELoss与nn.CrossEntropyLoss的区别
2021-04-16 16:29:28
![](https://img.aspxhome.com/file/2023/2/72802_0s.jpg)
用Python写一个简易版弹球游戏
2022-02-14 04:03:55
![](https://img.aspxhome.com/file/2023/9/97179_0s.jpg)
PyTorch之nn.ReLU与F.ReLU的区别介绍
2021-01-19 04:47:24
使用Math.max,Math.min获取数组中的最值实例
2023-09-03 23:23:59
vscode配置远程开发与免密登录的技巧
2023-04-29 02:43:41
![](https://img.aspxhome.com/file/2023/3/132403_0s.png)
MySQL无法存储emoji表情解决方案分析
2024-01-14 18:57:00
Python中处理Session和Cookie的方法
2023-09-09 00:51:18
反向传播BP学习算法Gradient Descent的推导过程
2022-09-08 09:51:06
![](https://img.aspxhome.com/file/2023/6/135186_0s.png)
Django创建一个后台的基本步骤记录
2021-03-19 02:13:38