티스토리 뷰

공부

[Java] round for percent

승가비 2020. 8. 10. 21:59
728x90
public static String percent(int a, int b) {
    return percent(a, b, 2);
}

public static String percent(int a, int b, int roundIndex) {
    return String.format("%."+ roundIndex +"f%%", a*1.0/b * 100);
}

https://coding-factory.tistory.com/250

 

[Java] 자바 소수점 n번째 자리까지 반올림하기

이번 포스팅에서는 자바에서 긴 소수를 반올림하여 n번째 자리까지 나타내는 방법에 대해 알아보겠습니다. 여러가지 방법이 있겠습니다만 Math.round();함수를 활용하거나 String.format(); 함수를 활��

coding-factory.tistory.com

 

728x90

'공부' 카테고리의 다른 글

[Sh] for  (0) 2020.08.10
[Sh] convert string to date  (0) 2020.08.10
[Python] requests  (0) 2020.08.10
[Python] POST json  (0) 2020.08.10
[Python] mail  (0) 2020.08.10
댓글