BigDecimal loses M suffix when converted to string using (str)


(str 1M) produces "1"
(str {:a 1M}) procuces "{:a 1M}"

The suffix is lost because str calls .toString directly: java.lang.BigDecimal does not know anything about M suffix.

`.toString` on map calls RT.print and that recursively calls RT.print for keys and values. RT.print has a special case for java.lang.BigDecimal, so it prints the suffix.




Alex Miller
February 18, 2019, 6:18 PM

CLJ-1201 is one such ticket

Alex Miller
February 18, 2019, 6:15 PM

Oh, well that’s considerably more interesting. As a workaround you could pr-str before you spit.

The question of edn printing is one that has come up several times (there might even be a ticket about it).
February 17, 2019, 10:21 PM

spit calls str, that's how I stumbled upon it.

It's trivial to make a pr-spit that calls pr-str, but isn't then spit kind of useless if its results can't be {{slurp}}ed back?

Daniel Sutton
February 17, 2019, 10:20 PM

This was discovered originally investigating `spit`. This particular behavior turned out not to be the culprit but was something noticed while investigating.

We were wondering if using spit for edn was a footgun or if it was a genuine bug.

Alex Miller
February 17, 2019, 10:10 PM

If you want to print a string that can later be read, normally you use pr-str. Some reason that’s not better here?

str intentionally does not have the expectation to be readable.

Your pinned fields
Click on the next to a field label to start pinning.








Affects versions