Simple Question

1. Britney Guest

## 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 -&#062; 0001 000<BR>12.5 -&#062; 0012 500<BR>1234.123 -&#062; 1234 123<BR><BR>I know this is probably easy, but I am having troubles. Any help would be good!

2. Steve Cimino Guest

## RE: Simple Question

Place your number into a string, and do a split on the decimal. Then you&#039ll 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

3. Junior Member
Join Date
Dec 1969
Posts
15

## 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!

4. Steve Cimino Guest

## RE: Simple Question

What you&#039re looking for is the FormatNumber command. Click on VBScript Reference in the toolbar on your left. Search for FormatNumber, and voila! you&#039ll have your leading zeros.

5. New ASP Guest

## RE: Simple Question

Let me try:<BR><BR>IF YOUR_NUMBER &#062; 1000 THEN<BR> YOUR_NUMBER = YOUR_NUMBER<BR>ELSE IF YOUR_NUMBER &#062; 100 THEN<BR> YOUR_NUMBER = "0" & CHAR(YOUR_NUMBER)<BR>ELSE IF YOUR_NUMBER &#062; 10 THEN<BR>:<BR>:<BR>OK?<BR><BR><BR><BR>

6. Birt Guest

## 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!

7. Senior Member
Join Date
Dec 1969
Posts
733

## RE: Simple Question

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

8. Steve Cimino Guest

## RE: Simple Question

9. New ASP Guest

## Simple Question not simple to me, :-)

I just can figure part of it.<BR><BR>&#060;%@LANGUAGE=VBSCRIPT%&#062;<BR>&#0 60;%MY=11.234<BR>VAR_1 = FORMATNUMBER(CINT(MY))<BR>VAR_2 = FORMATNUMBER((MY-CINT(MY))*1000,0)<BR>RESPONSE.WRITE VAR_1 & "<BR>"<BR>RESPONSE.WRITE VAR_2 & "<BR>"<BR>%&#062;<BR><BR>I still try to figure the leading zero.<BR>

10. Junior Member
Join Date
Dec 1969
Posts
15