How to convert a string representation of a number to a number in coldfusion?

StackOverflow https://stackoverflow.com/questions/2134058

  •  22-09-2019
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

I know you can use LSParseNumber:

<cfset string = "1,427.75">

<cfset number = LSParseNumber(string) * 100>

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top