xxxxxxxxxx
/*
* Example to print float value with 2 decimal points in Java
*/
public class JExercise {
public static void main(String[] args) {
float a = 1111;
float b = 7;
float result = a/b;
// Display result
System.out.println(result);
// Prints only 2 decimal points
System.out.printf("%.2f", result);
}
}
xxxxxxxxxx
#to round floats in Python you can use the "round" function. ex:
tax = 34.4563
tax = round(tax, 2)
#the number 2 at the end is how many digits are rounded.
#the variable "tax" would now be: 34.46
xxxxxxxxxx
// You can use .ToString("f2") to show 2 decimals of "f3" to show 3, etc.
float num = 123.24523;
Debug.Log(num.ToString("f2")); // Output: 123.24