26

I want to be able to convert a string number such as "1,427.76" to a number in coldfusion but the comma is making it fail. Is there a simple way to do it besides having to remove the comma?

<cfset string = "1,427.75">

<cfset number = string * 100>

The error occurs when trying to perform mathematical operations on it. If the comma is removed it works just fine but I'm getting the comma from a database calculation.

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
Scott Chantry
  • 1,115
  • 5
  • 16
  • 29

2 Answers2

52

I know you can use LSParseNumber:

<cfset string = "1,427.75">

<cfset number = LSParseNumber(string) * 100>
derivation
  • 4,362
  • 3
  • 27
  • 23
  • 2
    @Scott Chantry if derivation's answer worked for you, don't forget to choose it as the Accepted answer. :) – mwcz Jan 25 '10 at 20:51
10

Val() works as well for simple conversions where you don't care about locale, e.g. Val('123.45')

Matt Woodward
  • 234
  • 3
  • 4