当前位置:网站首页>验证浮点数输入
验证浮点数输入
2022-08-03 08:58:00 【我的天才女友】
浮点数输入在整数验证的基础上,将小数通过小数点分割成两部分,进行验证。
- . validint 通过小数点加对应的shell 文件引入对应的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
边栏推荐
猜你喜欢
随机推荐
IDEA的database使用教程(使用mysql数据库)
【LeetCode】101. Symmetric Binary Tree
数据监控平台
多媒体数据处理实验3:图像特征提取与检索
基于百度AI和QT的景物识别系统
【愚公系列】2022年07月 Go教学课程 026-结构体
面渣逆袭:MySQL六十六问,两万字+五十图详解
pytorch one-hot tips
110 MySQL interview questions and answers (continuous updates)
并发之固定运行和交替运行方案
Laya中关于摄像机跟随人物移动或者点击人物碰撞器触发事件的Demo
WPF 学习笔记《WPF样式基础》
“==”和equals的区别
内存模型之有序性
Exch:重命名或删除默认邮箱数据库
进程信息
计算机网络之网络安全
国内IT市场还有发展吗?有哪些创新好用的IT运维工具可以推荐?
Using pipreqs export requirements needed for the project. TXT (rather than the whole environment)
Alibaba Cloud SMS Sending









