Integrated Dynamics

Integrated Dynamics

63M Downloads

Add shorted number formatting

nskobelevs opened this issue · 2 comments

commented

Issue type:

  • ➕ Feature request

Short description:

A common use of a Display Panel is to display a number and in some cases (e.g. energy count) this numbers can get too large for the panel, impacting readability.

My suggestion is to add an operator to format numbers in a compact way.
Perhaps a second input specifying the number of decimal digits.

Input Output
1,254 1.2K
5,386,452 5.3M
3,385,215,385 3.3B

Java implements this natively since Java 12 which should make this a relatively easy feature to implement

import java.text.NumberFormat;
import java.util.Locale;
 
public class CompactNumberFormatExample {
 
    public static void main(String args[]) {
 
        NumberFormat nf = NumberFormat.getCompactNumberInstance(
                Locale.US, NumberFormat.Style.SHORT);
                
        nf.setMinimumFractionDigits(3);
        
        System.out.println("Result: " + nf.format(1254));
        System.out.println("Result: " + nf.format(5386452));
        System.out.println("Result: " + nf.format(3385215385L));
    }
}
Result: 1.254K
Result: 5.386M
Result: 3.385B
commented

I've raised a PR for this at #1221

commented

Thanks for the suggestion!