aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/isxander/yacl3/gui/ValueFormatters.java
blob: 988b257c603126a668617328e7d6c1ca27823780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package dev.isxander.yacl3.gui;

import dev.isxander.yacl3.api.controller.ValueFormatter;
import net.minecraft.network.chat.Component;

public final class ValueFormatters {
    public static ValueFormatter<Float> percent(int decimalPlaces) {
        return new PercentFormatter(decimalPlaces);
    }

    public record PercentFormatter(int decimalPlaces) implements ValueFormatter<Float> {
        public PercentFormatter() {
            this(1);
        }

        @Override
        public Component format(Float value) {
            return Component.literal(String.format("%." + decimalPlaces + "f%%", value * 100));
        }
    }
}