Skip to content

Commit 7eb0faa

Browse files
committed
feat: ABV 레벨 및 퍼센트 라벨링 기능 추가
1 parent 2364cb4 commit 7eb0faa

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.back.domain.user.support;
2+
3+
public final class AbvView {
4+
5+
private AbvView(){}
6+
7+
// 0~100%를 6단계로 매핑
8+
public static int levelOf(Double percent) {
9+
if (percent == null) return 1;
10+
11+
double x = Math.max(0, Math.min(100, percent));
12+
int p = (int) x;
13+
14+
if (p <= 10) return 1; // 0~10
15+
if (p <= 25) return 2; // 11~25
16+
if (p <= 45) return 3; // 26~45
17+
if (p <= 65) return 4; // 46~65
18+
if (p <= 85) return 5; // 66~85
19+
return 6; // 86~100
20+
}
21+
22+
// 화면용 "23.5%" 라벨
23+
public static String percentLabel(Double percent) {
24+
if (percent == null) return "0%";
25+
double x = Math.max(0.0, Math.min(100.0, percent));
26+
return (x % 1.0 == 0.0) ? String.format("%.0f%%", x) : String.format("%.1f%%", x);
27+
}
28+
}

0 commit comments

Comments
 (0)