cube
cube copied to clipboard
How to round off numbers to two decimal values
Hi,
I'm using a postgresql database. I'm calculating a percentage measure. How can I round it to 2 decimals?
@devopsprosiva You can use Postgres round function:
measures: {
percentage: {
sql: `round(${CUBE}.a / ${CUBE}.b, 2)`,
type: `number`
}
}
It works. Thanks for the help. I'll close the ticket.
In case of any similar issues with float variables, remember Postgres has some troubles with round. For me worked:
orderPrice: {
sql: `ROUND(order_price::numeric,2)`,
type: `sum`,
}
Described here: https://stackoverflow.com/questions/13113096/how-to-round-an-average-to-2-decimal-places-in-postgresql