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

/pay uses wrong currency format (decimals) #2355

Closed
robinstiege opened this issue Jan 5, 2019 · 2 comments · Fixed by Kyriakum/Essentials#1 or #5962
Closed

/pay uses wrong currency format (decimals) #2355

robinstiege opened this issue Jan 5, 2019 · 2 comments · Fixed by Kyriakum/Essentials#1 or #5962
Labels
status: open to PR Low priority enhancements that anyone is welcome to contribute. type: problem Problems that are not strictly bugs.

Comments

@robinstiege
Copy link

Information

Full output of /ess version:

[15:30:20 INFO]: Server Version: 1.12.2-R0.1-SNAPSHOT git-Spigot-dcd1643-e60fc34 (MC: 1.12.2)
[15:30:20 INFO]: EssentialsX Version: 2.16.0.6
[15:30:20 INFO]: LuckPerms Version: 4.3.17
[15:30:20 INFO]: Vault Version: 1.7.1-b91
[15:30:20 INFO]: EssentialsXSpawn Version: 2.16.0.6

EssentialsX config: https://gist.github.com/StiegeRobin/71f4c04d9df8aa123d96a4bc79538ca3

Details

Description
The command /pay doesn't take care of the currency-symbol-format-locale setting. When a player want to pay 50 cents seperated with a comma (like it's also displayed with /money), they will pay 50 euro instead.

Steps to reproduce

  1. Change the currency-symbol-format-locale to de-DE
  2. Change the minimum-pay-amount to at least 0.01
  3. Do /ess reload
  4. Pay someone a german formatted amount of money like /pay User 100,50 (these are 100 euro and 50 cents)
  5. You will see that you've paid 1.005,00 to that User instead of 100,50.

Expected behavior
As I've changed the currency format to german, the /pay command should also utilize it.

@mdcfe
Copy link
Member

mdcfe commented Jan 5, 2019

Thanks for opening a bug report.

EssentialsX currently removes all characters except the digits 0-9 and a decimal point:

String stringAmount = args[1].replaceAll("[^0-9\\.]", "");

It then uses Java's BigDecimal to parse the resulting amount into an actual money value:

It's the second part that's the issue - BigDecimal doesn't support , decimal places. Even if we stopped removing commas, we'd need to parse the command argument ourselves in order to solve this.

While this can't be fixed immediately, for now you can enable command confirmations, which will prompt users to type /pay confirm before sending money, prompting them with the correct amount (shown in the right currency format) before the payment is sent.

@mdcfe mdcfe added type: enhancement Features and feature requests. status: open to PR Low priority enhancements that anyone is welcome to contribute. labels Jan 5, 2019
@robinstiege
Copy link
Author

robinstiege commented Jan 5, 2019

Okay, I understand the problem. I tried the following:

String stringAmount = "1.234XYZ,50".replaceAll("[^0-9\\.\\,]", "");
BigDecimal bigDecimal = new BigDecimal(NumberFormat.getNumberInstance(Locale.GERMAN).parse(stringAmount).toString());
System.out.println(bigDecimal);

This gives me 1234.5 when I put "1.23XYZ4,50" and should be okay for further use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: open to PR Low priority enhancements that anyone is welcome to contribute. type: problem Problems that are not strictly bugs.
Projects
None yet
3 participants