当前位置:网站首页>Keep one decimal place and two decimal places
Keep one decimal place and two decimal places
2022-06-24 07:52:00 【Zhangxiaolang】
Keep one decimal place
export const inputTake2AfterDot =(obj:any)=>{
// return value.toString().match(/^\d+(?:\.\d{0,2})?/)
// eliminate " Numbers " and "." Characters other than
obj.value = obj.value.replace(/[^\d.]/g,"");
// Verify that the first character is a number
obj.value = obj.value.replace(/^\./g,"");
// Keep only the first , Remove excess
obj.value = obj.value.replace(/\.{2,}/g,".");
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
// Only one decimal can be entered
obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d).*$/,'$1$2.$3');
// return Math.round(value*Math.pow(10,2))/Math.pow(10,2)
};Keep two decimal places
export const inputTake2AfterDot =(obj:any)=>{
// return value.toString().match(/^\d+(?:\.\d{0,2})?/)
// eliminate " Numbers " and "." Characters other than
obj.value = obj.value.replace(/[^\d.]/g,"");
// Verify that the first character is a number
obj.value = obj.value.replace(/^\./g,"");
// Keep only the first , Remove excess
obj.value = obj.value.replace(/\.{2,}/g,".");
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
// Only two decimals can be entered
obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
// return Math.round(value*Math.pow(10,2))/Math.pow(10,2)
};The difference is at the end

Here I am antd Medium Input Called as follows :
<Input placeholder={' Working hours '} value={myTaskStore.workingHours} onChange={this.hoursChange} suffix=" Hours "
onInput={(e:any)=>{
let obj = e.target;
inputTake2AfterDot(obj)
}}
/>
边栏推荐
猜你喜欢

【008】表格数据逐行筛选,跳出for循环及跳过本次循环思路_#VBA

5-if语句(选择结构)

GPU is not used when the code is running

【NILM】非入侵式负荷分解模块nilmtk安装教程

RDD的执行原理

Exness: Powell insisted on his anti inflation commitment and pointed out that recession is possible

Part 2: drawing a window

Gossip: what happened to 3aC?

Introduction of model compression tool based on distiller

Basics of reptile B1 - scrapy (learning notes of station B)
随机推荐
Timer usage notes
Using kubeconfig files to organize cluster access
[C language] system date & time
第 2 篇:繪制一個窗口
从 jsonpath 和 xpath 到 SPL
Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its
Inline element, block element, inline block element
OpenGauss数据库在 CentOS 上的实践,配置篇
Mysql database recovery case sharing
What kind of experience is it when the Institute earns 20000 yuan a month!
关于h5页面苹果手机使用fixed定位tabbar最底部时遮挡内容问题
RDD的执行原理
常见的数组封装
【Django中运行scrapy框架,并将数据存入数据库】
Basics of reptile B1 - scrapy (learning notes of station B)
Tuple remarks
云开发谁是卧底小程序源码
Exness: Powell insisted on his anti inflation commitment and pointed out that recession is possible
Experience of Shenzhou computer
Wechat cloud hosting hot issues Q & A