Libraryless. Click here for Pure Java version (192L/2K).
1 | srecord Percent(double percent) {
|
2 | static Percent fromRatio(double ratio) { ret Percent(ratio*100); }
|
3 | static Percent fromRatio(double x, double y) { ret fromRatio(doubleRatio(x, y); }
|
4 | |
5 | void set(double percent) { percent = percent; }
|
6 | double get() { ret percent; }
|
7 | |
8 | toString {
|
9 | ret renderValue(percent) + " %"; |
10 | } |
11 | |
12 | S renderValue(double percent) { ret formatDouble(percent, 1); }
|
13 | |
14 | S renderWithDecimals aka withDecimals(int decimals) {
|
15 | ret formatDouble(percent, decimals) + " %"; |
16 | } |
17 | |
18 | S withExactDecimals(int decimals) {
|
19 | ret formatDoubleX(percent, decimals) + " %"; |
20 | } |
21 | |
22 | S oneDecimal() { ret withDecimals(1); }
|
23 | S exactlyOneDecimal() { ret withExactDecimals(1); }
|
24 | |
25 | static Percent ratio(double x, double y) {
|
26 | ret new Percent(doubleRatio(x, y)*100); |
27 | } |
28 | } |
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1035756 |
| Snippet name: | Percent |
| Eternal ID of this version: | #1035756/11 |
| Text MD5: | 2fbe6b269f0259467e91f08067d7f515 |
| Transpilation MD5: | 0419483aa351d5faf4cd21a4477673a2 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-07-25 15:59:47 |
| Source code size: | 826 bytes / 28 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 575 / 710 |
| Version history: | 10 change(s) |
| Referenced in: | [show references] |