Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Printing a number with commas 10,200 instead of 10000

Author
Message
Mega Publishers
16
Years of Service
User Offline
Joined: 17th Dec 2007
Location:
Posted: 4th Mar 2008 21:35
I tried using this code

rem

money=10000

money=money+200

print money

wait key

And every time, it prints the correct number, but I want the COMMA in their also. How do you code so that every time you have a number that is 4 digits or more, the appropriate commas are their? Ex 10,200 instead of 10200.

I need to know this because in my game, the player receives a paycheck of 200 every week, and I want his entire bank roll to be displayed showing, just like 10,200
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Mar 2008 22:45
write a function that converts the number to a string, and parse it to include the commas. There is no magic fix, it needs a little coding to achieve.
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 4th Mar 2008 23:13
ahhh, convert the integer to a string.

TOparse$ = var$(input)

then count how many characters in the string (ToParse$) variable,

leave the original variable as it is, but just change the output variable/string for displaying on screen..

Paul
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 5th Mar 2008 19:32
Try this:



It will return a formatted string of the integer that you give as a parameter. I know, I know, I shouldn't be so nice to someone who hasn't even made an attempt, but hey, I'm in a good mood.
Mega Publishers
16
Years of Service
User Offline
Joined: 17th Dec 2007
Location:
Posted: 5th Mar 2008 22:05
Thanks for the code AndrewT. I really appreciate it. The code is perfect except when the GetFormattedNumber is 3 digits or less, there is a comma in FRONT of the number.

For example the number “356” prints with a comma in front of it like ( ,356 )
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 5th Mar 2008 22:47
Go with my method! String commands i have found are quite quick :S

Paul
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 5th Mar 2008 22:57
Okay, here's a new one that will work with three-digit numbers:



Dabbler
17
Years of Service
User Offline
Joined: 3rd Mar 2007
Location: Minnesota
Posted: 5th Mar 2008 23:17
@AndrewT

You still get leading commas:




Whatever...
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 5th Mar 2008 23:36 Edited at: 5th Mar 2008 23:37
Ahh, okay, now it works:



Thanks for pointing that out.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Mar 2008 23:12
Something a little simpler & cleaner:


Dabbler
17
Years of Service
User Offline
Joined: 3rd Mar 2007
Location: Minnesota
Posted: 7th Mar 2008 03:40 Edited at: 7th Mar 2008 18:20
Or this?




Different codeing style, maybe.

Edit: I think I had an un-needed test. (removed it)

Another edit: I couldn't get to sleep, so:

And another edit: Corrections made for negative numbers. Same type of correction needed in the snippets from AndrewT and IanM.




Whatever...
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 8th Mar 2008 00:34


Paul
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Mar 2008 00:51 Edited at: 8th Mar 2008 01:11
Quote: "Corrections made for negative numbers"


Good point ...



Login to post a reply

Server time is: 2024-11-25 07:29:46
Your offset time is: 2024-11-25 07:29:46