My program basically takes an int studentID from a file and outputs it to a new file, but the problem is when the ID is entered as "00000" it is stored and prints as "0". Is there an easy way to keep the leading zeros when printing it?
Asked
Active
Viewed 47 times
1
-
8Store it as a `string` instead? – cigien Sep 24 '20 at 01:21
-
I fear there's nothing we can do other than suggest you save it as a string. Voting to close. Or at least add more details? How are you parsing the file etc... – Tony Tannous Sep 24 '20 at 01:22
-
numbers do not have "leading zeros". You can, however, display leading zeros by writing a little more code. – crashmstr Sep 24 '20 at 01:23
-
1Numbers don't have leading zeros. String representations of numbers do. There is no such number as `00000` or `01` or `004`. Those numbers are '0', `1` and `4`. If you want to left-pad with `0` to a specific width, you need to use a string instead. – Ken White Sep 24 '20 at 01:26
-
@KenWhite that makes sense, I wasn't sure if there was some way to store them though. I ended up just converting it to a string and I'll just convert it back if I need to use it as an int. – aons32 Sep 24 '20 at 01:33