当前位置:网站首页>Validate floating point input
Validate floating point input
2022-08-03 09:02:00 【my genius girlfriend】
Floating point input is based on integer validation,Divide the decimal into two parts by the decimal point,进行验证.
- . validint Add the corresponding by the decimal pointshell 文件引入对应的shell文件
#!/bin/bash
. validint
validfloat()
{
fvalue="$1"
if [ ! -z $(echo $fvalue | sed 's/[^.]//g') ] ; then
decimalPart="$(echo $fvalue | cut -d. -f1)"
fractionalPart="${fvalue#*\.}"
if [ ! -z $decimalPart ] ; then
if ! validint "$decimalPart" "" "" ; then
return 1
fi
fi
if [ "${fractionalPart%${fractionalPart#?}}" = "-" ] ; then
echo "Invalid floating-point number: '-' not allowed \ after decimal point" >&2
return 1
fi
if [ "$fractionalPart" != "" ] ; then
if ! validint "$fractionalPart" "0" "" ; then
return 1
fi
fi
else
if [ "$fvalue" = "-" ] ; then
echo "Invalid floating-point format." >&2 ; return 1
fi
if ! validint "$fvalue" "" "" ; then
return 1
fi
fi
return 0
}
if validfloat $1 ; then
echo "$1 is a valid floating-point value"
fi
exit 0
边栏推荐
- RViz报错: Error subscribing: Unable to load plugin for transport ‘compressed‘解决方法
- MySQL-存储过程-函数-
- 【TPC-DS】25张表的详细介绍,SQL的查询特征
- 计算机网络之网络安全
- MySQL-TCL语言-transaction control language事务控制语言
- HCIP练习02(OSPF)
- WPF 学习笔记《WPF样式基础》
- 【LeetCode】622.设计循环队列
- Scala parallel collections, parallel concurrency, thread safety issues, ThreadLocal
- 自动化测试浏览器驱动下载版本对应关系
猜你喜欢
响应式布局经典范例——巨幅背景大标题
AUC的两种计算方式
MySQL1
STP普通生成树安全特性— bpduguard特性 + bpdufilter特性 + guard root 特性 III loopguard技术( 详解+配置)
STP和RSTP的BPDU报文中flag位 对比+分析
手把手教你如何自制目标检测框架(从理论到实现)
LINGO 18.0 software installation package download and installation tutorial
获取JDcookie的方法
Batch PNG format can be converted to JPG format
pytorch one-hot 小技巧
随机推荐
HCIP练习(OSPF)
NFT到底有哪些实际用途?
dflow入门3——dpdispatcher插件
Redis分布式锁
面渣逆袭:MySQL六十六问,两万字+五十图详解
Add Modulo 10 (规律循环节,代码实现细节)
Gauva的ListenableFuture
C# 一周入门高级编程之《C#-继承》Day One
【LeetCode】226. Flip the binary tree
STP生成树(端口状态+端口角色+收敛机制 )|||| STP优化技术( uplinkfast技术+Portfast技术+backbonefast技术 )详解
10分钟带你入门chrome(谷歌)浏览器插件开发
AcWing 3391. 今年的第几天?(简单题)
机器学习(公式推导与代码实现)--sklearn机器学习库
gpnmb+ gpnmb-AT2 cell空转映射 上皮细胞的空转映射
Unity关于编辑器扩展自定义标签,方便扩展Inspector
HCIP练习02(OSPF)
redis键值出现 xacxedx00x05tx00&的解决方法
【LeetCode】101.对称二叉树
Batch PNG format can be converted to JPG format
MySQL-TCL语言-transaction control language事务控制语言