当前位置:网站首页>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)
}}
/>
边栏推荐
猜你喜欢

屏幕截图推荐—Snipaste

exness:鲍威尔坚持抗通胀承诺,指出衰退是可能的

1-4metasploitable2介绍

单片机STM32F103RB,BLDC直流电机控制器设计,原理图、源码和电路方案

爬虫基础B1——Scrapy(B站学习笔记)

Part 2: drawing a window

Introduction of model compression tool based on distiller

Hongmeng OS development III

ImportError: cannot import name ‘process_ pdf‘ from ‘pdfminer. Pdfinterp 'error completely resolved

Free ICP domain name filing interface
随机推荐
没有专业背景,还有机会成为机器学习工程师吗?
Chapter 3: drawing triangles
洛谷 P1051 谁拿了最多奖学金
鸿蒙os开发三
Pair class notes
Pyhton crawls to Adu (Li Yifeng) Weibo comments
用Ngrok 配置属于自己的免费外网域名
面试中的最常被问到的两种锁
线程的阻塞问题
Commandes de console communes UE
Jenkins is too old try it? Cloud native ci/cd Tekton
Specify IP when calling feign interface
随机数备注
某问答社区App x-zse-96签名分析
BOM notes
《canvas》之第3章 曲线图形
What challenges does the video streaming media platform face in transmitting HD video?
解决 These dependencies were not found: * core-js/modules/es6.array.fill in xxx 之类的问题
Explain the input attribute in PHP (hide the read-only restriction)
Exploration on Optimization of elastic expansion engineering