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’s:
global tcl_precision
set tcl_precision 3
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no way to globally change this.
If it is just for display purposes then use
sprintf("%.3f", $value);.For mathematical purposes, use
(int(($value * 1000.0) + 0.5) / 1000.0). This would work for positive numbers. You would need to change it to work with negative numbers though.