Convert decimal to string

# Thread: Convert decimal to string

1. Junior Member
Join Date
Dec 1969
Posts
17

## Convert decimal to string

hi!<BR><BR>how would you convert 61.95 to 00619500?<BR><BR>thanks,<BR>stussy :)

2. Senior Member
Join Date
Dec 1969
Posts
2,334

## Look into function formatnumber <eop>

.

3. Senior Member
Join Date
Dec 1969
Location
Indianapolis, IN
Posts
1,755

## RE: Convert decimal to string

"00" + Cstr((61.95 * 100)) + "00"

4. Senior Member
Join Date
Dec 1969
Posts
3,195

## RE: Convert decimal to string

Well if it was always that "fixed" format then something like<BR><BR> somestring = "00" & replace("61.95",".","") & "00"<BR><BR>if you are using a variable then<BR><BR> somestring = "00" & replace(cstr(yourvariable),".","") & "00"<BR><BR>That was quick and dirty..depending on what you are doing there are better ways ; )<BR><BR><BR>

5. Junior Member
Join Date
Dec 1969
Posts
17

## RE: Convert decimal to string

I&#039;m sorry, I should be more specific...<BR>This is what I&#039;m working with:<BR> Response.Write "&#060;td align=middle&#062;" & vbcrlf<BR> Response.Write "\$&#060;input readonly style=text-align:right type=text id=txtAmount" & ii & " name=txtAmount" & ii <BR> Response.Write " maxlength=8 size=8"<BR> Response.Write " value=" & oRS.Fields("Amount")<BR> Response.Write "&#062;&#060;/td&#062;" & vbcrlf<BR><BR>I also need to get rid of the decimal so, for example<BR>123.45 would become 01234500. I&#039;m trying to convert it before sending it to a text file.

6. Senior Member
Join Date
Dec 1969
Posts
11,247

## RE: Convert decimal to string

arrayofamount = split(oRS.Fields("amount"), ".")<BR>newamount = arrayofamount(0)<BR>do while len(newamount)&#060; 4<BR>newamount = "0" & newamount<BR>next<BR>newamount = newamount & arrayofamount & "00"

7. Senior Member
Join Date
Dec 1969
Posts
96,118

And how many digits do you need?<BR><BR>Anyway, something like this:<BR><BR>&#060;%<BR>num = Request("txtAmount" & someNumber)<BR>num = Round( num * 100 ) &#039; convert dollars to pennies<BR>str = Right( "00000" & num & "00", 8 ) &#039; leading/trailing zeroes; chop size<BR>%&#062;<BR><BR>And now "str" will be in the format you specified.<BR><BR>

8. Junior Member
Join Date
Dec 1969
Posts
17

## RE: Why the leading zero?

Thanks everyone! <BR><BR>Happy Holidays!<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•