
Simple Question
I have a database field that is ####.###. In the database field, if the number is 9.1, it is stored as 9.100. If the number is 21, it is stored as 21.000.<BR><BR>I need to display the number in this field as two numbers: the left four numbers, and the right three.<BR><BR>So, here are a couple of examples. The first number is as stored in the database, the next two what I need to display.<BR><BR>1.000 > 0001 000<BR>12.5 > 0012 500<BR>1234.123 > 1234 123<BR><BR>I know this is probably easy, but I am having troubles. Any help would be good!

RE: Simple Question
Place your number into a string, and do a split on the decimal. Then you'll have 2 seperate sets of numbers.<BR><BR>MyNewVariable = Split(CStr(MyOldNumber),".")<BR><BR>MyNewVariable( 0) = the first number<BR>MyNewVariable(1) = the second number

RE: Simple Question
Cool! How to I add zeros in front of the left number? Like if the number is 9, I need it to be 0009.<BR><BR>Thanx!

RE: Simple Question
What you're looking for is the FormatNumber command. Click on VBScript Reference in the toolbar on your left. Search for FormatNumber, and voila! you'll have your leading zeros.

RE: Simple Question
Let me try:<BR><BR>IF YOUR_NUMBER > 1000 THEN<BR> YOUR_NUMBER = YOUR_NUMBER<BR>ELSE IF YOUR_NUMBER > 100 THEN<BR> YOUR_NUMBER = "0" & CHAR(YOUR_NUMBER)<BR>ELSE IF YOUR_NUMBER > 10 THEN<BR>:<BR>:<BR>OK?<BR><BR><BR><BR>

RE: Simple Question
Thanx! Split seems to have problems with zero (eg 0.000), and I can only get format to work with the digits after the decimal. I will keep looking.<BR><BR>Thanx!

RE: Simple Question
I'm pretty sure you're right  formatnumber will not add leading 0's. I think you'll have to read the value into a string sort of like what's suggested below...<BR><BR>if (num >= 1000) then<BR>strnum = Cstr(num)<BR>else if (num >= 100) then<BR>strnum = "0" & Cstr(num)<BR>else if (num >= 10) then<BR>strnum = "00" & Cstr (num)<BR>else if (num >= 1) then<BR>strnum = "000" & Cstr (num)<BR>else<BR>strnum = "0000"<BR>end if

RE: Simple Question
I think you're right, you can't add leading zeros, only trailing. D'oh! Maybe I should read the docs before referring them to you! In any case, follow what New ASP told you with the If... then. Make sure your numbers are strings by using CStr.<BR><BR>Split will have the problem if you don't have a decimal in there, ie just 5. Instead, you may want to use the InStr function to find the decimal, and parse the numbers out from there. I assumed you always had numbers to the right of your decimal, which if you did, Split() is a quick solution. Try Instr, or format the number with formatnumber to include trailing zeros.<BR><BR>Sorry about the bad advice...

Simple Question not simple to me, :)
I just can figure part of it.<BR><BR><%@LANGUAGE=VBSCRIPT%><BR>� 60;%MY=11.234<BR>VAR_1 = FORMATNUMBER(CINT(MY))<BR>VAR_2 = FORMATNUMBER((MYCINT(MY))*1000,0)<BR>RESPONSE.WRITE VAR_1 & "<BR>"<BR>RESPONSE.WRITE VAR_2 & "<BR>"<BR>%><BR><BR>I still try to figure the leading zero.<BR>

RE: Simple Question
No such thing as bad advice! I probably was not clear.<BR><BR>Thanx for all your help
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

