skip to Main Content

I want to format a double value returned from db to 2 decimal places

I tried number_format($amount,2) but it didn’t work

2

Answers


  1. Try and explicitly cast the double value to float like mentioned in this thread here

    Also, check what type is the $amount variable in your example..

    Login or Signup to reply.
  2. Use the php number_format

    number_format($number, 2, '.', ',');
    
    
    1. 2 decimal places.
    2. ‘.’ for decimal separator
    3. ‘,’ for thousand separator
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search