Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex to add 2 point decimalisation

Status
Not open for further replies.

SteveJR

Programmer
Aug 13, 2001
72
0
0
GB
Hi,

Could someone please provide a regex that can convert a string of numbers into a 2 point decimalisation. For example, convert 100 into 1.00, convert 100000 into 1000.00

I have searched on the forums but could not find a regex that does a search/replace for my needs.

Many thanks for your help,

Steve
 
Hi

You mean to insert a dot ( . ) character before the last 2 character ?
Perl:
[navy]$nr[/navy] [teal]=~[/teal] [b]s[/b][fuchsia]/(..)$/.$1/[/fuchsia][teal];[/teal]
But note that unless you want to check other things too, there is no need for regular expression :
Perl:
[b]substr[/b] [navy]$nr[/navy][teal],[/teal] [teal]-[/teal][purple]2[/purple][teal],[/teal] [purple]0[/purple][teal],[/teal] [green][i]'.'[/i][/green][teal];[/teal]
As you said nothing about any string length requirement, I just ignored the case of handling shorter strings.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top