Make dots between numbers in php

前端 未结 2 1105
误落风尘
误落风尘 2021-01-21 18:22

I would like to make dots between my total value.

If i have 425000 i would like it to show as 425.000

Is there a function in php that implodes dots for numbers o

相关标签:
2条回答
  • 2021-01-21 18:42

    Use number_format for this:

    $number =  425000;
    echo number_format( $number, 0, '', '.' );
    

    The above example means: format the number, using 0 decimal places, an empty string as the decimal point (as we're not using decimal places anyway), and use . as the thousands separator.

    Unless of course I misunderstood your intent, and you want to format the number as a number with 3 decimal places:

    $number =  425000;
    echo number_format( $number, 3, '.', '' );
    

    The above example means: format the number, using 3 decimal places, . as the decimal point (default), and an empty string as the thousands separator (defaults to ,).

    If the default thousands separator is good enough for you, you can just use 1:

    $number =  425000;
    echo number_format( $number, 3 );
    


    1) Mind you: number_format accepts either 1, 2 or 4 parameters, not 3.

    0 讨论(0)
  • 2021-01-21 18:44

    I guess you're looking for the number_format function.

    0 讨论(0)
提交回复
热议问题