How to format a number as percentage with 2 decimal places in presto?

by jasen_gottlieb , in category: Third Party Scripts , 6 months ago

How to format a number as percentage with 2 decimal places in presto?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , 6 months ago

@jasen_gottlieb 

In Presto, you can format a number as a percentage with 2 decimal places using the FORMAT function as follows:

1
SELECT FORMAT(your_number * 100, '99.99') || '%' AS percentage_formatted


Replace your_number with the number that you want to format as a percentage. The * 100 part is used to convert the number to a percentage (e.g., 0.5 becomes 50%). The '99.99' format string ensures that the number is displayed with 2 decimal places.


For example, if you have a number 0.5678 that you want to format as a percentage with 2 decimal places, you can use the following SQL query:

1
SELECT FORMAT(0.5678 * 100, '99.99') || '%' AS percentage_formatted


This will output 56.78%.

Related Threads:

How to determine number of days in a month in presto?
How to format seconds as integer into hh:mm:ss in presto?
How to format number in PostgreSQL?
How to format number in a grafana table?
How to fetch an unlimited number of rows in presto?
How to use percentage in a laravel query?