开发者

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

开发者 https://www.devze.com 2022-12-18 12:49 出处:网络
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?

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 comm开发者_运维知识库a 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')

0

精彩评论

暂无评论...
验证码 换一张
取 消