views:

520

answers:

1

Hi!

I need to format decimal numbers with patterns in J2ME just like java DecimalFormat.

I see an option to port Format/NumberFormat/DecimalFormat.

Can you suggest ready to use implementation or library?

Thanks!

A: 

So, I've manage to port desktop java implementation: bbnumberformat:

    String[] patterns = new String[] { "#,#00.00#", "0.0;(0.0)",
            "0.###E0" };
    DecimalFormat format = (DecimalFormat) DecimalFormat
            .getNumberInstance();
    double value = -12.321;
    for (int i = 0; i < patterns.length; i++) {
        String pattern = patterns[i];
        format.applyPattern(pattern);
        String text = "Pattern: " + pattern 
        + " Sample: "+format.format(value)+"\n";
        add(new LabelField(text));
    }

alt text

Max Gontar