Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BigDecimal result = new BigDecimal("50.5399999").setScale(2, BigDecimal.ROUND_HALF_UP);
- static long round(double a)
- double d = 50.539999; // or however many 9's, it doesn't matter
- int dollars = (int)d;
- double frac = d - dollars;
- int cents = (int)((frac * 100) + 0.5);
- long money = 5054;
- long cents = money % 100;
- long dollars = money / 100; // this works due to integer/long truncation
- System.out.printf("$%d.%02.d", dollars, cents);
- double value = .539999;
- int result = (int) (value*100);
- if(((value*100)%result)>.5)
- result++;
- num = .53999999;
- int_num = (int)(num * 100); // cast to integer, however you do it in Java
- compare_num = (int_num + 0.5) / 100;
- dollars_and_cents = round(100*a)/100
- cents = (dollars_and_cents-(int)dollars_and_cents)*100
- double d = 50.539999;
- long cents = (long)(d * 100 + 0.5);
- double rounded = cents/100;
Add Comment
Please, Sign In to add comment