Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
Expand Down Expand Up @@ -137,15 +138,11 @@ public CurrencyDetails getCurrency(String currencyCode) {
*/
public static String getValueWithTruncateDecimals(String value, int noOfDecimals) {
if (value != null) {
String returnValue = value;
int decimalLength = 0;
if (value.contains(".")) {
decimalLength = value.substring(value.indexOf(".")).length();
}
if (decimalLength > noOfDecimals) {
returnValue = value.substring(0, value.indexOf(".") + noOfDecimals + 1);
}
return returnValue;
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(noOfDecimals);
nf.setRoundingMode(RoundingMode.HALF_UP);
double amount = Double.parseDouble(value);
return nf.format(amount);
} else {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ public void testGetNumberOfFractionDigits_NoDigitDecimal(){
@Test
public void testFXRateWithFourDecimal()
{
assertThat("1.2345",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",4)));
assertThat("1.2346",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",4)));
assertThat("1.234",is(CurrencyParser.getValueWithTruncateDecimals("1.234",4)));
assertThat("1.0000",is(CurrencyParser.getValueWithTruncateDecimals("1.000056",4)));
assertThat("1.0001",is(CurrencyParser.getValueWithTruncateDecimals("1.000056",4)));
assertThat("1",is(CurrencyParser.getValueWithTruncateDecimals("1",4)));
assertThat("",is(CurrencyParser.getValueWithTruncateDecimals(null,4)));
assertThat("1.234",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",3)));
assertThat("1.235",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",3)));
assertThat("1.23",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",2)));
assertThat("1.2",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",1)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public void onReceive(Context context, Intent intent) {
allOf(withId(R.id.exchange_rate_label), withText(R.string.mobileFXRateLabel))))));
onView(withId(R.id.list_foreign_exchange)).check(
matches(atPosition(0,
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("$1 USD = $1.2912 CAD"))))));
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("$1 USD = $1.2913 CAD"))))));
onView(withId(R.id.amount_label)).check(matches(withText(R.string.mobileConfirmDetailsAmount)));
onView(withId(R.id.amount_value)).check(matches(withText("$152.20 CAD")));
onView(withId(R.id.fee_label)).check(matches(withText(R.string.mobileConfirmDetailsFee)));
Expand Down