2

this might seem a very naive question but I am having a hard time to figure this out. I have a float value 37.50378 in my PostgreSQL database. When I am trying to fetch this value in my Nodejs application it gives me 37.5038. I want to fetch the exact number without rounding off the decimal digits. How do I do that? The data type of the column in Postgres is Real.

EDIT

I am using Knex schema builder and using float(column, precision, scale) to create a column(to store above-said value). I have tried different numbers for precision and scale just in case that's causing the above-said behavior. But every time I tried to fetch the value 37.50378, all I get back is 37.5038.

Thanks.

2 Answers 2

1

You may want to use double(column) in knex, which is translated to double precision in postgres.

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

Comments

0

This is because of the real 4-byte precision. See PostgreSQL Numeric Types.

It's got nothing to do with Node.js or its PostgreSQL driver.

3 Comments

Thanks for your reply @vitaly-t. I am using Knex.js for building the schema and float(column, precision, scale) to create the column. No matter what precision and scale number I provide it always create a column with data type real in Postgres. Do I need to change anything in my schema building?
@harsh that's an entirely separate question. I'm not familiar with knex to answer that.
No problem @vitaly-t. Thanks for your input.

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.