Results 1 to 3 of 3

Thread: Change number format

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    Change number format

    How can I change number format?

    I want to change number 3.4893 to 2 dight only until become 3.49

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    if you're printing it:
    PHP Code:
    printf("%.2f"$number); 
    if you're just using it internally for calculations...
    PHP Code:
    sprintf("%.2f"$number); 
    or check out the number_format function

  3. #3
    If you are using it for a MySQL query, use FORMAT():
    FORMAT(X,D)
    Formats the number X to a format like '#,###,###.##', rounded to D decimals. If D is 0, the result will have no decimal point or fractional part:
    mysql> SELECT FORMAT(12332.123456, 4);
    -> '12,332.1235'
    mysql> SELECT FORMAT(12332.1,4);
    -> '12,332.1000'
    mysql> SELECT FORMAT(12332.2,0);
    -> '12,332'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width