how to trunck a float number with one decimal place
I need to trunk a float number with one decimal place. For eg: i have a float number called total=95.20004. my result should be 95.2. I have tried with the DecimalForma, but it is not working out. Kindly help me to resolve this issue.
You should be more specific as to what you want to do with your truncated number.
Do you want to put it in a String? Do you want to print it to the screen and keep the exact value in your variable? Do you want to truncate the result in your double variable?
Only printing to the screen: System.printf("%.1f", number);
Truncated number as a String: String.format("%.1f", number); and assign it to a String reference variable.
Truncate the result in your double variable: number = (int) (number * 10) / 10.0;
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...