iT邦幫忙

0

Batch四則運算

@echo off
set /p a=請輸入數量:
echo %a%
set /a b=%a%/18
echo %b%

假如a=180,b=a/18=10,是整數
那假如是a=1000,b=a/18=55.5556,是有餘數的部分
那請問可以讓餘數部分無條件進位變成56嗎?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2021-06-19 08:11:30

Ref:Batch rounding a number

@echo off
set "number_to_round=55.5556"
echo %number_to_round%

for /f "tokens=1,2 delims=." %%a  in ("%number_to_round%") do (
  set first_part=%%a
  set second_part=%%b
)

if defined second_part ( 
    set /a rounded=%first_part%+1
) else ( 
    set /a rounded=%first_part%
)

echo %rounded%

我要發表回答

立即登入回答