Funclate, Json and BigDecimals

10 views
Skip to first unread message

Stuart Ervine

unread,
Jun 6, 2014, 11:28:01 AM6/6/14
to utter...@googlegroups.com
Hi all,

I think I'm being dumb. I'm trying to format a model, which contains some BigDecimals, into json. The BDs are coming out in scientific format. Is there a way output the BD's plainString to the json?

Test:

    @Test
    public void jsonFormattingOfSmallNumbers() throws Exception {
        Number value = new BigDecimal("0.00000005");
        Model model = model().add("value", value);
        String json = Json.toJson(model);
        assertThat(json, containsString("0.00000005"));
    }

Cheers
S. 

Tom Malone

unread,
Jun 6, 2014, 12:55:23 PM6/6/14
to utter...@googlegroups.com
Its because the toString on bigdecimals defaults to engineering format on certain strings I have included a patch which calls toPlainString which fixs Stuarts problem and includes his tests, not sure if its the right way to fix it or if it should be fixed.

Tom


--
You received this message because you are subscribed to the Google Groups "utterlyidle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to utterlyidle...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Making_bigdecimals_output_as_numbers_not_engineering_format.patch
Reply all
Reply to author
Forward
0 new messages