skip to Main Content

The value saved in the database is 0.0 as numeric data type, I need to retrieve 0.00 with the select. is there a way in postgres?

2

Answers


  1. SELECT to_char(0.0, '90.99');
    

    See here for documentation.

    Login or Signup to reply.
  2. Formatting a value for being rendered in a specific way in the frontend is not a concern of the database.

    Instead, use String#% to control how the float should be formatted in the frontend. In your case, when you want to render the float with two digits, you can use this formatting rule:

    float = 0.0
    "%0.2f" % float
    #=> "0.00"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search