mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 15:00:30 +01:00
Merge pull request #1936 from ManfredKarrer/fix-formatting-issue
Convert long dash to short dash for minus values
This commit is contained in:
commit
108ce1d72c
5 changed files with 25 additions and 15 deletions
|
@ -17,6 +17,8 @@
|
|||
|
||||
package bisq.core.monetary;
|
||||
|
||||
import bisq.core.util.BSFormatter;
|
||||
|
||||
import org.bitcoinj.core.Monetary;
|
||||
import org.bitcoinj.utils.MonetaryFormat;
|
||||
|
||||
|
@ -86,10 +88,10 @@ public final class Altcoin implements Monetary, Comparable<Altcoin> {
|
|||
*
|
||||
* @throws IllegalArgumentException if you try to specify fractional satoshis, or a value out of range.
|
||||
*/
|
||||
public static Altcoin parseAltcoin(final String currencyCode, String inputValue) {
|
||||
inputValue = inputValue.replace(",", ".");
|
||||
public static Altcoin parseAltcoin(final String currencyCode, String input) {
|
||||
String cleaned = BSFormatter.convertCharsForNumber(input);
|
||||
try {
|
||||
long val = new BigDecimal(inputValue).movePointRight(SMALLEST_UNIT_EXPONENT)
|
||||
long val = new BigDecimal(cleaned).movePointRight(SMALLEST_UNIT_EXPONENT)
|
||||
.toBigIntegerExact().longValue();
|
||||
return Altcoin.valueOf(currencyCode, val);
|
||||
} catch (ArithmeticException e) {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package bisq.core.monetary;
|
||||
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.util.BSFormatter;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.core.Monetary;
|
||||
|
@ -31,12 +32,11 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
/**
|
||||
* Bitcoin price value with variable precision.
|
||||
*
|
||||
* <p>
|
||||
* <br/>
|
||||
* We wrap an object implementing the {@link Monetary} interface from bitcoinj. We respect the
|
||||
* number of decimal digits of precision specified in the {@code smallestUnitExponent()}, defined in
|
||||
* those classes, like {@link Fiat} or {@link Altcoin}.
|
||||
*
|
||||
*/
|
||||
public class Price extends MonetaryWrapper implements Comparable<Price> {
|
||||
private static final Logger log = LoggerFactory.getLogger(Price.class);
|
||||
|
@ -54,11 +54,11 @@ public class Price extends MonetaryWrapper implements Comparable<Price> {
|
|||
* Parse the Bitcoin {@code Price} given a {@code currencyCode} and {@code inputValue}.
|
||||
*
|
||||
* @param currencyCode The currency code to parse, e.g "USD" or "LTC".
|
||||
* @param value The value to parse as a String, e.g "2.54" or "-0.0001".
|
||||
* @return The parsed Price.
|
||||
* @param input The input value to parse as a String, e.g "2.54" or "-0.0001".
|
||||
* @return The parsed Price.
|
||||
*/
|
||||
public static Price parse(String currencyCode, String value) {
|
||||
final String cleaned = value.replace(",", ".");
|
||||
public static Price parse(String currencyCode, String input) {
|
||||
String cleaned = BSFormatter.convertCharsForNumber(input);
|
||||
if (CurrencyUtil.isFiatCurrency(currencyCode))
|
||||
return new Price(Fiat.parseFiat(currencyCode, cleaned));
|
||||
else
|
||||
|
@ -70,7 +70,7 @@ public class Price extends MonetaryWrapper implements Comparable<Price> {
|
|||
*
|
||||
* @param currencyCode The currency code to parse, e.g "USD" or "LTC".
|
||||
* @param value The value to parse.
|
||||
* @return The parsed Price.
|
||||
* @return The parsed Price.
|
||||
*/
|
||||
public static Price valueOf(String currencyCode, long value) {
|
||||
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package bisq.core.monetary;
|
||||
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.util.BSFormatter;
|
||||
|
||||
import org.bitcoinj.core.Monetary;
|
||||
import org.bitcoinj.utils.Fiat;
|
||||
|
@ -34,8 +35,8 @@ public class Volume extends MonetaryWrapper implements Comparable<Volume> {
|
|||
super(monetary);
|
||||
}
|
||||
|
||||
public static Volume parse(String inputValue, String currencyCode) {
|
||||
final String cleaned = inputValue.replace(",", ".");
|
||||
public static Volume parse(String input, String currencyCode) {
|
||||
String cleaned = BSFormatter.convertCharsForNumber(input);
|
||||
if (CurrencyUtil.isFiatCurrency(currencyCode))
|
||||
return new Volume(Fiat.parseFiat(currencyCode, cleaned));
|
||||
else
|
||||
|
|
|
@ -562,9 +562,15 @@ public class BSFormatter {
|
|||
return value;
|
||||
}
|
||||
|
||||
protected String cleanDoubleInput(String input) {
|
||||
input = input.replace(",", ".");
|
||||
public static String convertCharsForNumber(String input) {
|
||||
// Some languages like finnish use the long dash for the minus
|
||||
input = input.replace("−", "-");
|
||||
input = StringUtils.deleteWhitespace(input);
|
||||
return input.replace(",", ".");
|
||||
}
|
||||
|
||||
protected String cleanDoubleInput(String input) {
|
||||
input = convertCharsForNumber(input);
|
||||
if (input.equals("."))
|
||||
input = input.replace(".", "0.");
|
||||
if (input.equals("-."))
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package bisq.desktop.util.validation;
|
||||
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.util.BSFormatter;
|
||||
import bisq.core.util.validation.InputValidator;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +30,7 @@ import bisq.core.util.validation.InputValidator;
|
|||
public abstract class NumberValidator extends InputValidator {
|
||||
|
||||
protected String cleanInput(String input) {
|
||||
return input.replace(",", ".").trim();
|
||||
return BSFormatter.convertCharsForNumber(input);
|
||||
}
|
||||
|
||||
protected ValidationResult validateIfNumber(String input) {
|
||||
|
|
Loading…
Add table
Reference in a new issue