variable number of decimals

LabKey Support Forum (Inactive)
variable number of decimals Ben Bimber  2010-11-05 09:28
Status: Closed
 
we have a table of weights. weights >1kg are accurate to 2 decimals. weights less than 1 are accurate to 3. in a perfect world, weights would display like:

17.20
0.394
0.300

as opposed to
17.2
0.394
0.3

Several users dont like the fact that since number columns are right aligned, the 0.394 and 0.3 are not lined up. Is there anything we can do about that? I think I could add a format string to force 3 decimals; however, we would only want 3 decimals for numbers <1, and 2 decimals for numbers >1.

Are there tricks I'm not thinking of? Thanks for the help.
 
 
jeckels responded:  2010-11-05 10:33
Hi Ben,

We don't have support for your specific scenario right now. Underneath, we're using java.text.DecimalFormat:

http://download.oracle.com/javase/6/docs/api/java/text/DecimalFormat.html

It doesn't have support for significant digits, and even if it did, this scenario is a tweak on the "usual" scenario of having a fixed number of significant digits.

I think your current choices are to use either 0.000 or 0.00#. The former will always include three decimal places, even for values that are > 1. The latter will omit the third decimal place for values < 1 if it's 0.

Supporting two different formats based on the value wouldn't be that difficult if this is worth prioritizing for a future release.

Thanks,
Josh
 
Ben Bimber responded:  2010-11-05 10:35
hi josh,

i doubt this will make any sort of priority list any time soon. i suspect this may be a matter taste taste people become accustomed to; however, we shall see.