How do I set the floating point precision in Perl?

前端 未结 5 1965
失恋的感觉
失恋的感觉 2020-12-18 20:54

Is there a way to set a Perl script\'s floating point precision (to 3 digits), without having to change it specifically for every variable?

Something similar to TCL\

5条回答
  •  既然无缘
    2020-12-18 21:29

    Treat the result as a string and use substr. Like this:

    $result = substr($result,0,3);
    

    If you want to do rounding, do it as string too. Just get the next character and decide.

提交回复
热议问题