Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I limit decimal precision in processing?

I have several floating point values in processing with decimal places beyond 8 digits.

How can I round these values to the tenths before using text() to draw them?

like image 251
dangerChihuahua007 Avatar asked Dec 27 '22 04:12

dangerChihuahua007


1 Answers

You can format a floating point (float or double) x with 2 decimal places like this:

String.format("%.2f", x)

This'll give you a String.

For example:

String.format("%.2f", 12.34567)

returns the string "12.35".

like image 135
Laurence Gonsalves Avatar answered Jan 11 '23 18:01

Laurence Gonsalves