Skip to content

[V5] Decimal field is returning as string #2764

Answered by skrenek
CodeAkio asked this question in Help
Discussion options

You must be logged in to vote

Some database drivers (Postgres, for example) will return decimals as strings due to possible loss of precision with floating point numbers. If you're using Postgres, we've worked around this by adding the following to the register function of the app's AppProvider. It will convert the strings to numbers before they hit the Adonis framework. If you're not using Postgres, your mileage may vary, but hopefully this sends you in the right direction.

public register () {
  const types = require('pg').types
  types.setTypeParser(types.builtins.NUMERIC, function (val) {
    return Number(val)
  })
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by CodeAkio
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants