user input in #.### format

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

user input in #.### format

#1 Post by batchcc » 13 Nov 2015 20:05

I have a batch file that collects user inputas seen below

Code: Select all

Set /p whole-number=
Set /p decimal=

However when the user enters the decimal for example 0.5 the rest of the script won't work because the decimal must look like this 0.500is there a way to force the batch file to add the extra zero's so the user doesn't have to type them after the 0.5? Thanks

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: user input in #.### format

#2 Post by Squashman » 13 Nov 2015 20:51

Pad zeros to the right and then substring the number of characters you need.

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: user input in #.### format

#3 Post by batchcc » 14 Nov 2015 17:27

Code: Select all

set "decimal=%decimal%00"
set "decimal=%decimal:~3%"

I'm sorry I have never done this before is this correct?

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: user input in #.### format

#4 Post by ShadowThief » 14 Nov 2015 18:42

Close. What you have says to grab everything from the third character to the end. You want

Code: Select all

set "decimal=%decimal:~0,3%"

Post Reply