Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Number Formatting
#1
Is there any specific way to display all numbers in a "000" format? I tried the USING command, but it doesn't seem to have that. What I'm trying to do is load files that are sorted as "File001.dat, File002.dat, File003.dat .......... File010.dat, File011.dat".
Reply
#2
well I thought that USING "000" would force the leading zeros to appear. Hmmm

if not you can always do something like:

Code:
IF NumericValue < 10 THEN
   LeadingZeroes = "00"
ELSE IF NumericValue > 9 AND NumericValue <=99 THEN
   LeadingZeroes = "0"
ELSE
   LeadingZeroes = ""
END IF

FileName = "FILE" + LeadingZeroes + TRIM$(STR$(NumericValue))+".dat"

Should do the trick :-)
hen they say it can't be done, THAT's when they call me ;-).

[Image: kaffee.gif]
[Image: mystikshadows.png]

need hosting: http://www.jc-hosting.net
All about ASCII: http://www.ascii-world.com
Reply
#3
Alright, I'll go with that. Thanks. =]
Reply
#4
You're very welcome :-)
hen they say it can't be done, THAT's when they call me ;-).

[Image: kaffee.gif]
[Image: mystikshadows.png]

need hosting: http://www.jc-hosting.net
All about ASCII: http://www.ascii-world.com
Reply
#5
Rokkuman,

Here's a solution based on the same idea, but much simpler:
Code:
FileName$ = "FILE" + RIGHT$("000" + LTRIM$(STR$(NumericValue)) ,3)+".dat"
Note: You really only need 2 zeros up front, "00",
but using "000" makes what you're doing clearer.
*****
Reply
#6
I thought doing a STR$(Numeric) left a leading space for the possible minus (-) sign)
hen they say it can't be done, THAT's when they call me ;-).

[Image: kaffee.gif]
[Image: mystikshadows.png]

need hosting: http://www.jc-hosting.net
All about ASCII: http://www.ascii-world.com
Reply
#7
Not in FB. In QB, it left a leading space for the minus sign, but in FB, that is changed. This makes things easier so you don't have to do this:
Code:
RIGHT$(STR$(variable), LEN(STR$(variable)) - 1)

This removes the first character and should only be used in QB if you know that a result will be positive. Otherwise, you would probably use a FUNCTION or a SUB to convert it to a string if you convert to strings numerous times:

Code:
FUNCTION varToStr$(variable)
IF SGN(variable) < 0 THEN
    varToStr$ = STR$(variable)
ELSE
    varToStr$ = RIGHT$(STR$(variable), LEN(STR$(variable)) - 1)
END IF
END FUNCTION

Edit: Untested, but it should work.
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Reply
#8
O_o in qb people used ltrim$( str$( somenum% ) ) :roll: :wink:
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply
#9
Quote:O_o in qb people used ltrim$( str$( somenum% ) ) :roll: :wink:
Except for people who didn't know that LTRIM$ existed. :wink:
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Reply
#10
Another way to do it is:

Code:
Const NumberOfZeros = 3


FileName$ = "file" + String$(NumberOfZeros - Len(LTrim$(Str$(NumericalValue))), "0") + LTrim$(Str$(NumericalValue))

Easily adjust number of preceding zeros Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)