package example.ark_smartbridge_listener;

import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Component
public class NumberFormatter {

    public String formatNumber(BigDecimal value) {
        if (value.compareTo(new BigDecimal("1000000")) > 0) {
            return value.divide(new BigDecimal("1000000"), 2, BigDecimal.ROUND_DOWN).toPlainString() + "M";

        } else if (value.compareTo(new BigDecimal("1000")) > 0) {
            return value.divide(new BigDecimal("1000"), 2, BigDecimal.ROUND_DOWN).toPlainString() + "k";
        } else {
            return value.setScale(2, RoundingMode.DOWN).toPlainString();
        }
    }

}

@@ -358,25 +358,25 @@
 %221000000%22), 
-2
+0
 , BigDecimal
@@ -534,17 +534,17 @@
 1000%22), 
-2
+0
 , BigDec

use zero scale for large numbers