简体   繁体   中英

Convert String to BigDecimal ruby

I am making a rails site and I am trying to take a text box input and convert it to a big decimal value to pass to a backend service however when I take the input (params[:amount]) and do what I think should convert this to a BigDecimal I get an error when attempting to call the service saying "error cannot convert String to BigDecimal" on the line of the service call. See approximate code below

@amt = BigDecimal(params[:amount])

Service.call(@amt)

The error message indicates it is expecting a string in Service.call and wants to do the conversion itself. Assuming you have reasons for creating @amt (such as validation/error checking), I would pass in @amt.to_s and see what happens

Barring that, we need the code behind Service.call() to know more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM