Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecimalFormat Does Not Suppress Negative Sign #167

Open
mlvn23 opened this issue Apr 23, 2020 · 9 comments
Open

DecimalFormat Does Not Suppress Negative Sign #167

mlvn23 opened this issue Apr 23, 2020 · 9 comments

Comments

@mlvn23
Copy link

mlvn23 commented Apr 23, 2020

This test case passes in JVM but not in JS:

        val uut2 = new DecimalFormat("0.00; 0.00")
        checkEquals("7.65", uut2.format(7.65))
        checkEquals(" 7.65", uut2.format(-7.65))
        checkEquals("98765.23", uut2.format(98765.234))
        checkEquals(" 98765.23", uut2.format(-98765.234))
@cquiroz
Copy link
Owner

cquiroz commented Apr 23, 2020

Thanks for the report, I tested this and you're right. Are you interested on fixing it?

@mlvn23
Copy link
Author

mlvn23 commented Apr 24, 2020

Apparently, this also does not work:

        val uut0 = new DecimalFormat("000")
        checkEquals("001", uut0.format(1))

@mlvn23
Copy link
Author

mlvn23 commented Apr 24, 2020

I looked at the JavaDoc and it does not look trivial to implement it from scratch. I saw a couple of implementation in JavaScript in Github. One is has MIT and another has BSD-3. Android SDK is under Apache, which might be compatible with BSD? Do you think it's okay to port it?

cquiroz added a commit that referenced this issue Apr 24, 2020
Signed-off-by: Carlos Quiroz <carlos.m.quiroz@gmail.com>
@cquiroz
Copy link
Owner

cquiroz commented Apr 24, 2020

I agree it is not trivial, the algorithm was created by hand and obviously the parsing of the format is missing some cases.
Unfortunately I don't have time to purse this
About porting please be mindful of the scala.js rules:
https://github.com/scala-js/scala-js/blob/master/DEVELOPING.md

Essentially you can't look at jdk code or harmony

@mlvn23
Copy link
Author

mlvn23 commented Apr 24, 2020

If you're okay with an external JS lib, this implementation appears to be good:

https://github.com/DeloitteDigitalAPAC/DecimalFormat

They did it with a formalized parser and lots of tests. It also accepts a locale as input.

I did a browserify with it and ran it in ScalaJS with some of my unit test and so far so good. I'll try to do a CI test later this week to see if it holds up.

@cquiroz
Copy link
Owner

cquiroz commented May 5, 2020

That's interesting. I wouldn't expect a js library implementing a java spec. It maybe used I think provided it doesn't add up too much in terms of size.
I want to support scala-native so this may need to go into a js specific version

@mlvn23
Copy link
Author

mlvn23 commented May 8, 2020

I've been using it for two weeks trying different things and it seems solid. About 14KB minimized.

@cquiroz
Copy link
Owner

cquiroz commented May 12, 2020

That sounds great, if you want to submit a PR it would be ok, Let's keep the old version in a cross project for a future scala native release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants