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

Oracle-高级SQL限定查询

5-if语句(选择结构)

热赛道上的冷思考:乘数效应才是东数西算的根本要求

Cloud development who is the source code of undercover applet

Part 2: drawing a window

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

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

云开发谁是卧底小程序源码

用Ngrok 配置属于自己的免费外网域名

免费ICP域名备案查接口
随机推荐
[测试开发]初识软件测试
[C language] system date & time
IndexError: Target 7 is out of bounds.
力扣(LeetCode)174. 地下城游戏(2022.06.23)
What challenges does the video streaming media platform face in transmitting HD video?
UE common console commands
The startup mode of cloudbase init is \Cloudbase init has hidden dangers
简单的折射效果
LeetCode 207:课程表(拓扑排序判断是否成环)
Exness: Powell insisted on his anti inflation commitment and pointed out that recession is possible
Moonwell Artemis is now online moonbeam network
使用 kubeconfig 文件组织集群访问
【Django中运行scrapy框架,并将数据存入数据库】
Jenkins is too old try it? Cloud native ci/cd Tekton
What kind of experience is it when the Institute earns 20000 yuan a month!
Basics of reptile B1 - scrapy (learning notes of station B)
AWTK 最新动态:Grid 控件新用法
【资料上新】迅为基于3568开发板的NPU开发资料全面升级
第 2 篇:繪制一個窗口
Terminal network in VPN client connection settings of router