Remove trailing zeros in decimal value with changing length

前端 未结 15 2921
醉话见心
醉话见心 2020-12-05 04:36

I have a procedure I am doing that displays odds but the client wants only significant digits to be shown. So, 1.50 would show as \'1.5\' and 1.00 would show as \'1\'.

15条回答
  •  甜味超标
    2020-12-05 05:07

    If you are using PHP as the scripting language you may use the following:

    $var = (float)$var_having_extra_0; // $var = (float) 17.5000
    

    Or use the PHP floatval function:

    $var = floatval($var_having_extra_0); // $var = floatval(17.5000)
    

提交回复
热议问题