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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert string number to value 1

Status
Not open for further replies.

simon551

IS-IT--Management
May 4, 2005
249
Having a problem with numeric values that contain commas.
This returns 2.
Code:
$(document).ready(function() {
		var x = "2,915.75";
			x= parseFloat(x);
		alert(x);
});

Obviously I need it to return "2915.75". I'm not good with regex. Is there a simple function to do this?
 
Hi

Code:
$[teal]([/teal]document[teal]).[/teal][COLOR=darkgoldenrod]ready[/color][teal]([/teal][b]function[/b][teal]()[/teal] [teal]{[/teal]
        [b]var[/b] x [teal]=[/teal] [green][i]"2,915.75"[/i][/green][teal];[/teal]
            x[teal]=[/teal] [COLOR=darkgoldenrod]parseFloat[/color][teal]([/teal]x[highlight][teal].[/teal][COLOR=darkgoldenrod]replace[/color][teal]([/teal][fuchsia]/,/g[/fuchsia][teal],[/teal][green][i]''[/i][/green][teal])[/teal][/highlight][teal]);[/teal]
        [COLOR=darkgoldenrod]alert[/color][teal]([/teal]x[teal]);[/teal]
[teal]}[/teal][teal]);[/teal]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top