Closed takle-sb1 closed 4 months ago
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.
Btw, using double
for money is not recommended. Either use a dedicated money type or BigDecimal
to avoid rounding errors.
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.parse
instead, it sucessfully parses the number.
Mmh. I tested this on 8.0.352-zulu
. Which JVM are you using?
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)
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?
No, it's impossible to type the minus sign using any sane method. Everyone just uses the normal hyphen (ascii 45).
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.
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.
Cheers good point.
I presume you also don't use a non-breaking space to separate thousands?
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.
Thanks for the explanation.
The fix should be in the latest version of cucumber-jvm
.
Attempting to use a negative number in a step that expects a
{double}
, in a test case written in Norwegian, doesn't work.Minimal example:
👓 What did you see?
Cucumber is unable to parse the number:
✅ What did you expect to see?
The text should be parsed to double value
-2.11
.📦 Which tool/library version are you using?
Cucumber-java 12.15