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