Percent from decimal? PHP

前端 未结 5 1963
感情败类
感情败类 2020-12-31 04:10

Trying to convert this \"0.274509817\" to a nice precentage like 27%

The string is a dynamic value from an API.

相关标签:
5条回答
  • 2020-12-31 04:18

    What's the problem with intval($a * 100) . '%'?

    0 讨论(0)
  • 2020-12-31 04:22
    $number = 0.274509817;
    echo round( $number * 100 ), '%';
    
    0 讨论(0)
  • 2020-12-31 04:23
    round((float)$value * 100) . '%'
    
    0 讨论(0)
  • 2020-12-31 04:23

    and after that, append

    "%" 
    

    to get the percent sign (e.g. if used with sprintf).

    0 讨论(0)
  • 2020-12-31 04:29
    $percent = round((float)$str * 100 ) . '%';
    

    Where $str = "0.274509817"

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