15

I am creating a table using Knex.JS, and the table has a column for a currency value.

For example, here is the column amount:

knex.schema.createTable('payment', function(table) {
  table.increments();
  table.float('amount');
})

Currently, I am using the float type, but I'd like to use the numeric type. What is the equivalent of the numeric type in Knex.JS?

Thanks.

1 Answer 1

16

For currency decimal is best match, so your code may look like:

knex.schema.createTable('payment', function(table) {
  table.increments();
  table.decimal('amount',14,2); // e.g. 14 positions, 2 for the cents
});

see http://knexjs.org/#Schema-decimal

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

1 Comment

I was confused about this as well. From the postgres docs: "The types decimal and numeric are equivalent. Both types are part of the SQL standard."

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.