1

I want to use the numeric type of Postgresql 9.3 but my parser :

private val Account403Parser: RowParser[Account403] = {
  get[Long]("id") ~
  get[Float]("amount") map {
  case id ~ amount =>
    Account403.apply(id, amount)
}

doesn't work since anorm can't convert from java.math.BigDecimal to Float.

Here is the error that I get :

[RuntimeException: TypeDoesNotMatch(Cannot convert 9.5: class java.math.BigDecimal to Float for column ColumnName(account403.amount,Some(amount)))]

How can I change my parser to make it convert from the java.math.BigDecimal type to the Float type?

1
  • More numeric conversions are available in master. Commented Nov 29, 2014 at 1:34

1 Answer 1

1

According to the type-compatibility matrix in the documentation you should use

BigDecimal, Double or Long to assign a BigDecimal.

Or you could cast to real (4-byte floating point number) on the Postgres side: amount::real, thereby losing some precision. Not sure about the syntax in scala.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.