当前位置:网站首页>验证浮点数输入
验证浮点数输入
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
边栏推荐
- 面渣逆袭:MySQL六十六问,两万字+五十图详解
- LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之二:编码实现
- Exception: Dataset not found.解决办法
- Qt 下拉复选框(MultiSelectComboBox)(一) 实现下拉框多选,搜索下拉框内容
- The window of the chosen data flow
- 并发之固定运行和交替运行方案
- FusionAccess软件架构、FusionAccess必须配置的四个组件、桌面发放流程、虚拟机组类型、桌面组类型
- dflow入门4——recurse&reuse&conditional
- 10 minutes to get you started chrome (Google) browser plug-in development
- 110 MySQL interview questions and answers (continuous updates)
猜你喜欢

The Transformer, BERT, GPT paper intensive reading notes

【愚公系列】2022年07月 Go教学课程 026-结构体

10 minutes to get you started chrome (Google) browser plug-in development

Docker starts mysql

redis键值出现 xacxedx00x05tx00&的解决方法

IDEA的database使用教程(使用mysql数据库)

Redis集群概念与搭建

10分钟带你入门chrome(谷歌)浏览器插件开发

Eject stubborn hard drives with diskpart's offline command

WPF 学习笔记《WPF样式基础》
随机推荐
dflow部署简记
Exception: Dataset not found. Solution
MySQL-DDL数据定义语言-约束
响应式布局经典范例——巨幅背景大标题
编程踩坑合集
牛客 - 最佳直播时间 (差分)
scala 并行集合、并行并发、线程安全问题、ThreadLocal
The display of the article list and the basics of creating articles and article details
线程介绍与使用
“==”和equals的区别
BOM系列之localStorage
dflow入门5——Big step & Big parameter
Add Modulo 10 (规律循环节,代码实现细节)
【LeetCode】101.对称二叉树
gpnmb+ gpnmb-AT2 cell空转映射 上皮细胞的空转映射
Guava的Service
110道 MySQL面试题及答案 (持续更新)
FusionAccess软件架构、FusionAccess必须配置的四个组件、桌面发放流程、虚拟机组类型、桌面组类型
Using pipreqs export requirements needed for the project. TXT (rather than the whole environment)
多媒体数据处理实验4:LSH索引