BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Displaying Cash with Commas"
, by modius
Sick of presenting cash as $500000 instead of the much more legible $500,000? Well this code does exactly that.
Code
;*************************************************************************** ;* cashcommas.bb: Present Cash with Commas ;* Coded By: tnb98@yahoo.com ;* Last Updated: 21/10/2002 ;* Ever wanted to display 5000 like 5,000? Well this function turns ;* any number (up to 999999999) into a string and allows it to ;* be displayed with commas ;* ;* BUGS ;* ------ ;* 1) There is also a problem when you try to return the conj$, I dunno why. ;* 2) It doesn't do negative numbers, but with a little code it could do. ;* code is free of charge, use it as you like ;* ;*************************************************************************** ; enable graphics mode Graphics 800,600,16 AppTitle "Display Cash using Commas" ; Default Font Variables Global fntVerdana fntVerdana=LoadFont("Verdana",12,False,False,False) SetFont fntVerdana ; End Font Variables ; amount. should display as 100,000 amount=100000 ; where to put it on the screen x=100 y=100 While Not KeyHit(1) Cls displayCash (amount, x, y) Flip Wend ; Clear all the fonts from memory FreeFont fntVerdana End Function displayCash (mynumb, x, y) maxnumb=999999999 If mynumb>maxnumb Then mynumb=maxnumb If mynumb >= 1000 And mynumb < 10000 Then myleft = 1 mymid=0 myright = 3 End If If mynumb >= 10000 And mynumb < 100000 Then myleft = 2 mymid=0 myright = 3 End If If mynumb >= 100000 And mynumb < 1000000 Then myleft = 3 mymid=0 myright = 3 End If If mynumb>=1000000 And mynumb<1000000 Then myleft=1 mymid=0 myright=6 End If If mynumb>=10000000 And myNumb<100000000 Then myleft=2 mymid=3 myright=3 End If If mynumb>=100000000 And mynumb<=999999999 Then myleft=3 mymid=3 myright=3 End If If mymid=0 Then my1$ = Left$(Str(mynumb), myleft) my2$ = Right$(Str(mynumb), myright) If mynumb >= 1000 And mynumb<=maxnumb Then conj$ = my1$ + "," + my2$ Else conj$ = Str$(mynumb) End If Else ; strips out the length of the text and displays it for ; numbers over And including 10 million ; dump the number into a temporary variable test$=Str(mynumb) ; get the left my1$=Left$(Str(mynumb), myleft) ; get the middle my2$=Mid$(test$,4,3) ; get the right my3$=Right$(Str(mynumb), myright) ; put it altogether If mynumb>=1000 And mynumb<=maxnumb Then conj$=my1$ + "," + my2$ + "," + my3$ Else conj$=Str$(mynumb) End If End If ; ensure its still a String dconj$=Str$(conj$) ; Print dconj$ Text x,y, dconj$ End Function
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations