help regarding rounding off numbers

java

Solution

You should do this as part of the formatting - the floating point number itself doesn't have any concept of "two decimal places".

For example, you can use a `DecimalFormat` with a pattern of "#0.00":

import java.text.*;

public class Test
{
    public static void main(String[] args)
    {
        float y = 12.34567f;
        NumberFormat formatter = new DecimalFormat("#0.00");
        System.out.println(formatter.format(y));
    }
}

Problem

float per = (num / (float)totbrwdbksint) * 100; i m getting the value of per as say 29.475342 . i want it to round off upto two decimal places only.like 29.48 .how to achieve this?

Original source