Q:

Alternate method for toFixed function in Java

I have the values where the last 2 digits valve must be round figured. This functionality I can achieve in JavaScript toFixed(6) . But how we can achieve the same in java code
Example:
Input=75.74306816000052
Input =26.910038862000476

Output=75.743070
Output=26.910040

Code:
BigDecimal Output= new BigDecimal(Input).setScale(6, RoundingMode.HALF_EVEN)

But the output values coming hear are
75.743068
26.910038

A:

As the comments under your post already state, the rounding in java is correct and i am not sure what you want to achieve. But this gives you the output you expect:
public static void main(String[] args) throws Exception {
    String Input="75.74306816000052";
    String Input2 = "26.910038862000476";
    BigDecimal Output= new BigDecimal(Input).setScale(5, RoundingMode.HALF_EVEN);
    System.out.println(Output.setScale(6)); //75.743070
    BigDecimal Output2= new BigDecimal(Input2).setScale(5, RoundingMode.HALF_EVEN);
    System.out.println(Output2.setScale(6)); //26.910040
}

