当前位置:网站首页>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)
}}
/>
边栏推荐
- What kind of experience is it when the Institute earns 20000 yuan a month!
- Exness: Powell insisted on his anti inflation commitment and pointed out that recession is possible
- atguigu----16-自定义指令
- BOM笔记
- Los Angeles p1051 who won the most Scholarships
- Mousse shares listed on Shenzhen Stock Exchange: gross profit margin continued to decline, and marketing failed in the first quarter of 2022
- 2022年PMP项目管理考试敏捷知识点(1)
- 第 3 篇:绘制三角形
- 慕思股份在深交所上市:毛利率持续下滑,2022年一季度营销失利
- 10. Tencent cloud IOT device side learning - firmware upgrade
猜你喜欢
随机推荐
Moonwell Artemis is now online moonbeam network
Duilib display memory picture
Open cooperation and win-win future | Fuxin Kunpeng joins Jinlan organization
调用Feign接口时指定ip
日期、时间库使用备注
chrono 使用备注
Pyhton crawls to Adu (Li Yifeng) Weibo comments
Baidu map, coordinate inversion, picking coordinate position
洛谷 P1051 谁拿了最多奖学金
Hongmeng development IV
智能指针备注
. No main manifest attribute in jar
慕思股份在深交所上市:毛利率持续下滑,2022年一季度营销失利
How to realize high stability and high concurrency of live video streaming transmission and viewing?
5-if语句(选择结构)
语料库数据处理个案实例(句子检索相关个案)
UE common console commands
Experience of Shenzhou computer
GPU is not used when the code is running
《canvas》之第4章 线条操作









