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

Description

(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.

Environment

None

Activity

Show:
Alex Miller
February 18, 2019, 9:10 AM

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.

Daniel Sutton
February 18, 2019, 9:20 AM

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.

dottedmag@dottedmag.net
February 18, 2019, 9:21 AM

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?

Alex Miller
February 19, 2019, 5:15 AM

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).

Alex Miller
February 19, 2019, 5:18 AM

CLJ-1201 is one such ticket

Assignee

Unassigned

Reporter

dottedmag@dottedmag.net

Labels

None

Approval

Triaged

Patch

None

Affects versions

Priority

Minor