Coder Social home page Coder Social logo

Comments (11)

mpkorstanje avatar mpkorstanje commented on July 23, 2024

I can't seem to reproduce this. Because your feature is in Norwegian, Cuucmber uses the no locale.

So you should be able to run this without any problems:

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

public class LocaleTest {

  public static void main(String[] args) throws ParseException {
    Locale locale = Locale.forLanguageTag("no");
    NumberFormat format = DecimalFormat.getNumberInstance(locale);
    Number parsed = format.parse("-2,11");
    System.out.println(parsed);
  }

}

Which leads me to think that perhaps your editor replaced - (ascii 45) with something else.

To debug this, you can put a breakpoint in the NumberParser.parseFloat method, and look at the code points in the string.

final class NumberParser {
private final NumberFormat numberFormat;
NumberParser(Locale locale) {
numberFormat = DecimalFormat.getNumberInstance(locale);
if (numberFormat instanceof DecimalFormat) {
DecimalFormat decimalFormat = (DecimalFormat) numberFormat;
decimalFormat.setParseBigDecimal(true);
}
}
double parseDouble(String s) {
return parse(s).doubleValue();
}

Btw, using double for money is not recommended. Either use a dedicated money type or BigDecimal to avoid rounding errors.

from cucumber-expressions.

takle-sb1 avatar takle-sb1 commented on July 23, 2024

No, it's definitely ASCII 45. The entire string is [45, 50, 44, 49, 49] when viewing it in the debugger.

I noticed that when using the debugger to feed a unicode minus sign (U+2212) to numberFormat.parseinstead, it sucessfully parses the number.

from cucumber-expressions.

mpkorstanje avatar mpkorstanje commented on July 23, 2024

Mmh. I tested this on 8.0.352-zulu. Which JVM are you using?

from cucumber-expressions.

takle-sb1 avatar takle-sb1 commented on July 23, 2024
openjdk version "17.0.5" 2022-10-18
OpenJDK Runtime Environment Temurin-17.0.5+8 (build 17.0.5+8)
OpenJDK 64-Bit Server VM Temurin-17.0.5+8 (build 17.0.5+8, mixed mode, sharing)

from cucumber-expressions.

mpkorstanje avatar mpkorstanje commented on July 23, 2024

Looks like a variation of https://bugs.openjdk.org/browse/JDK-8298849.

For my Native dutch the hypen is used. Do Norwegian keyboards have a dedicated key for the minus sign or is that just the hypen?

from cucumber-expressions.

takle-sb1 avatar takle-sb1 commented on July 23, 2024

No, it's impossible to type the minus sign using any sane method. Everyone just uses the normal hyphen (ascii 45).

from cucumber-expressions.

mpkorstanje avatar mpkorstanje commented on July 23, 2024

Oh that is just lovely. This also applies to:

Northern Sami (Latin, Norway)
Northern Sami (Norway)
Norwegian Bokmål (Svalbard & Jan Mayen)
Basque
Persian
Croatian (Latin, Croatia)
Norwegian
Swiss German
Norwegian (Latin, Norway)
Slovenian
Swiss German (France)
Estonian (Estonia)
Slovenian (Slovenia)
Finnish (Latin, Finland)
Norwegian Bokmål (Norway)
Persian (Arabic, Iran)
Finnish (Finland)
Colognian (Germany)
Romansh (Latin, Switzerland)
Norwegian (Norway)
Lithuanian (Lithuania)
Colognian (Latin, Germany)
Croatian (Croatia)
Slovenian (Latin, Slovenia)
Croatian
Lithuanian
Swiss German (Liechtenstein)
Croatian (Bosnia & Herzegovina)
Swedish (Sweden)
Persian (Afghanistan)
Swedish
Basque (Latin, Spain)
Swedish (Latin, Sweden)
Persian (Iran)
Swedish (Finland)
Faroese (Latin, Faroe Islands)
Colognian
Swiss German (Switzerland)
Estonian
Finnish
Romansh
Norwegian Bokmål (Latin, Norway)
Romansh (Switzerland)
Estonian (Latin, Estonia)
Northern Sami (Finland)
Lithuanian (Latin, Lithuania)
Northern Sami (Sweden)
Northern Sami
Faroese (Denmark)
Faroese (Faroe Islands)
Faroese
Basque (Spain)
Swiss German (Latin, Switzerland)
Swedish (Åland Islands)

So I'm half minded to override the minus sign to a dash when it is used.

from cucumber-expressions.

takle-sb1 avatar takle-sb1 commented on July 23, 2024

That will probably work. It looks like it needs to be a hyphen in order to be recognized as a parameter anyway, i.e., replacing the hyphen with a unicode minus in the Gherkin file doesn't work.

from cucumber-expressions.

mpkorstanje avatar mpkorstanje commented on July 23, 2024

Cheers good point.

I presume you also don't use a non-breaking space to separate thousands?

from cucumber-expressions.

takle-sb1 avatar takle-sb1 commented on July 23, 2024

I presume you also don't use a non-breaking space to separate thousands?

That's correct, it has the same problem with not being possible to type on a keyboard, so only the most techically minded people will use it in practice. Using a regular space isn't uncommon, though, as is using a period.

from cucumber-expressions.

mpkorstanje avatar mpkorstanje commented on July 23, 2024

Thanks for the explanation.

The fix should be in the latest version of cucumber-jvm.

from cucumber-expressions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.