lucky icon indicating copy to clipboard operation
lucky copied to clipboard

Malformed format string with 0 precision

Open jwoertink opened this issue 3 years ago • 2 comments

https://github.com/luckyframework/lucky/blob/dd61285fd250f6b18a8b9ceb80e2484e50773e84/src/lucky/page_helpers/number_to_currency.cr#L24

Passing a precision of 0 will those that error "%.0f" % 100.0

jwoertink avatar Sep 08 '22 21:09 jwoertink

Here's a play link with the error: https://play.crystal-lang.org/#/r/dqf8

stephendolan avatar Sep 08 '22 21:09 stephendolan

Turns out this is a Crystal bug... maybe fixed by https://github.com/crystal-lang/crystal/pull/12448 ?

I tried against 1.6.0-dev and it works, but 1.5.1 it's broken.

❯ ./bin/crystal eval 'pp "%.0f" % 100.0'
Using compiled compiler at .build/crystal
"100"

❯ crystal eval 'pp "%.0f" % 100.0'
Unhandled exception: Malformed format string - %'0' (ArgumentError)

jwoertink avatar Sep 08 '22 22:09 jwoertink

Closing this since it'll be fixed by Crystal 1.6 being released next week.

jwoertink avatar Sep 27 '22 00:09 jwoertink