thurmc
thurmc

Reputation: 525

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)

Upvotes: 0

Views: 1881

Answers (1)

Jeff Price
Jeff Price

Reputation: 3229

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.

Upvotes: 1

Related Questions