underscore.string icon indicating copy to clipboard operation
underscore.string copied to clipboard

.sprintf and .numberFormat should work on numeric strings.

Open erichiggins opened this issue 12 years ago • 1 comments

The current behavior of .sprintf and numberFormat is briefly demonstrated below. Providing numeric strings throws an error.

> ._str.sprintf("%.2f", 0.5);
"0.50"
> ._str.sprintf("%.2f", "0.5");
Error: [_.sprintf] expecting number but found string

With respect to keeping the utility functions as simple as possible, this behavior is considered 'correct'. Since JS is loose-typed, at least having an option to run these would be beneficial to developers. I'd prefer not to cast all inputs with parseFloat or parseInt before using the utility, when it does it already just after it's own type check.

erichiggins avatar Jan 29 '13 23:01 erichiggins

I agree! Any improvement on this so far?

Thank you.

marceloschmidt avatar Oct 03 '14 13:10 marceloschmidt