-2

How to round a number in Java?

  • Input: 0.655308; Expected output: 65.53.
  • Input: 1.0583104; Expected output: 105.83.

In power builder compute expression I use

 act_qty  *work_hour /
 if (on_hour < work_hour )  /
  sec_setm_gole_qty ,4)

How to run it in Java?

Rafael Tavares
  • 5,678
  • 4
  • 32
  • 48

2 Answers2

1

I would just multiply the value with 100

double roundedValue = value * 100;
System.out.printf("%.2f", roundedValue);
Mardydu
  • 45
  • 1
  • 7
0

String.format("%.2f%%",value*100)?

Benjamin Urquhart
  • 1,626
  • 12
  • 18
  • Minor tweak: ```String.format("%.2f%%",value*100)```. If you're using .format you might as well have it produce the whole string, rather than concatenating a percent sign on after formatting. –  May 05 '19 at 13:21
  • It was that easy to get a literal % into a format string? – Benjamin Urquhart May 05 '19 at 14:06