Replacing right 2 numbers no matter what.

# Thread: Replacing right 2 numbers no matter what.

1. Senior Member
Join Date
Dec 1969
Posts
190

## Replacing right 2 numbers no matter what.

Hi all,<BR><BR>I see the FAQ&#039;s and such on REGEX replacing. and I know how to replace matched characters.<BR><BR>But how do I replace the right two numbers no matter what they are? And show the entire amount?<BR><BR>Like say prior to replacing the price is \$3,415 but after replacing it is \$3,495 ?<BR><BR>Is there a way to do it without using REGEX?<BR><BR>Thank you<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
1,944

## RE: Replacing right 2 numbers no matter what.

AMT = "3415"<BR>AMT = "\$" + LEFT(AMT,2) + "WHATEVERYOUWANTTOPUT"<BR>RESPONSE.WRITE AMT

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

## FormatNumber(Number, 2) (eop)

.

4. Senior Member
Join Date
Dec 1969
Posts
190

## RE: Replacing right 2 numbers no matter what.

Thank you Sreenivas,<BR><BR>Only one problem with it - sometimes the price may be 3,415 and other times it may be 5 digits - like 13,514

5. Senior Member
Join Date
Dec 1969
Posts
190

## RE: Replacing right 2 numbers no matter what.

Ok, I got it,<BR><BR>Took your solution, added in a count then an IF.<BR><BR>&#060;% <BR> strPrice=(rs("fldOurCost")+4000)<BR> IF LEN(strPrice)=4 THEN<BR> strPrice="\$" + LEFT(strPrice,2)+"95"<BR> ELSE<BR> strPrice="\$" + Left(strPrice,3)+"95"<BR> End IF<BR>%&#062;<BR><BR>Thank you both

6. Senior Member
Join Date
Dec 1969
Posts
1,944

## If not left(), take right()...

amt = "35,345"<BR>newamt = "\$" + substr(amt,1,len(amt)-2) + "whateveryouwanttoput"<BR>response.write newamt<BR><BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
1,944

## that may not work always

if the number is more than 5 digit one, then<BR><BR>say 232323, then you end up <BR><BR>232XX and not 2323XX which is incorrect.look at my other post.

8. Senior Member
Join Date
Dec 1969
Posts
1,944

## Oops!

replace the function name "substr" with "mid"<BR><BR>amt = "35,345"<BR>newamt = "\$" + mid(amt,1,len(amt)-2) + "whateveryouwanttoput"<BR>response.write newamt

9. Senior Member
Join Date
Dec 1969
Posts
190

## RE: that may not work always

very true - its not much of a concern, if we have vehicles that are 6 digits - its time to get rid of it wholesale.<BR><BR>However - tried out your other mentioned code - and it worked perfect. I also assume it is much faster than mine.<BR><BR>Thank you.

#### Posting Permissions

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