batch-file - 在批处理文件中将数字转换为不同的数字
问题描述
这必须是非常基本的,但我似乎无法找到完成这项工作的方法
我的批处理脚本是这样的:
@echo off
echo Type In Desired Volume And Press Enter
echo.
echo 0 = 0 %%
echo 1 = 100 %%
echo 0.10 = 10 %%
echo 0.65 = 65 %%
echo.
set /p input=
echo %input% > "C:\SetVol\Source\Volume.txt
0
我想让用户输入一个介于和之间的数字,而100
不是例如0.10
10% 的音量,以使其更加用户友好。0.10
但是如果用户输入,我仍然需要将10
.
谷歌似乎不再是我最好的朋友,我们似乎无法就此进行交流。
如果有人可以帮助我获得首发,那就太好了。
解决方案
您可以在循环中使用选择来制作基于键的“滑块”,然后修改变量值以包含0.
前缀或1
使用 if 条件:
@Echo off
set "volume=50"
:Volume
cls
Echo( Current volume: %Volume%%% [I]ncrease [D]ecrease [C]ontinue
For /f "delims=" %%G in ('Choice /N /C:IDC')Do (
If "%%G"=="I" If not %Volume% GEQ 100 Set /A Volume+=1
If "%%G"=="D" If not %Volume% LEQ 0 Set /A Volume-=1
If not "%%G"=="C" Goto :Volume
)
IF %volume% Equ 100 ( Set "Volume=1" )Else If %volume% LSS 10 (
Set "Volume=0.0%Volume%"
) Else Set "Volume=0.%Volume%"
:#your script here
对于 NTFS 系统,一种将最后设置的卷存储在备用数据流中并在返回时重新分配最后一个值的变体:
@Echo off
set "volume=50"
For /f "Usebackq delims=" %%G in ("%~f0:Volume")Do Set "%%G"
:Volume
cls
Echo( Current volume: %Volume%%% [I]ncrease [D]ecrease [C]ontinue
For /f "delims=" %%G in ('Choice /N /C:IDC')Do (
If "%%G"=="I" If not %Volume% GEQ 100 Set /A Volume+=1
If "%%G"=="D" If not %Volume% LEQ 0 Set /A Volume-=1
If not "%%G"=="C" Goto :Volume
)
Set Volume >"%~f0:Volume"
IF %volume% Equ 100 ( Set "Volume=1" )Else If %volume% LSS 10 (
Set "Volume=0.0%Volume%"
) Else Set "Volume=0.%Volume%"
:#your script here
注意:使用这种输入方式,不能输入无效的输入。
推荐阅读
- mocha.js - webdriverio v5 + mocha 中的缓慢加载 qa 环境超时
- python - CUML 拟合函数抛出 cp.full TypeError
- responsive - 如何在移动设备中制作响应式视图并将滚动条仅添加到笔记本电脑
- c++ - 指向对象和析构函数的指针
- python - 如何使用 copy_expert 将数据加载到列名中具有特殊字符的 postgresql 表中?
- reactjs - 如何读取 TextInput 中的值?
- yaml - 为不同的 GitHub Actions 作业共享相同的步骤
- javascript - 无法读取未定义的属性 OnSnapshot
- qml - 如何在 ScrollView 和 Flow 中使用 MouseArea
- json - JSON Powershell 内存问题