Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMy MICDS
20,571 PointsI know I've done the problem correctly, however, the test is seeing weird ASCII text at the end of each conversion.
for instance:
Expected: a string containing "1,00 (Euro)"
but: was "1,00áÇ (Euro)"
and:
Expected: is "First is $1.00 (USD) which is $15,48 (Argentine Peso)"
but: was "First is $1.00 (USD) which is $á15,48 (Argentine Peso)"
1 Answer
Ben Basty
23,772 PointsTo resolve this error :
Expected: a string containing "1,00 (Euro)"
but: was "1,00 € (Euro)"
Here is how i resolved it.
public static Function<Integer, String> createPriceConverter(Locale locale, BigDecimal usdRate) {
// TODO: Examine the hardcoded `getArgentinaPriceConverter` method
// TODO: Using the arguments passed into this method return a function that will work for any locale and rate
return usdPrice -> {
Currency currentCurrency = Currency.getInstance(locale);
NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale);
if (currencyFormatter instanceof DecimalFormat) {
DecimalFormat df = (DecimalFormat) currencyFormatter;
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
dfs.setCurrencySymbol("");
df.setDecimalFormatSymbols(dfs);
df.applyPattern(".00");
}
return String.format("%s (%s)", currencyFormatter.format(usdRate), currentCurrency.getDisplayName()
);
};
}
And Don't forget to import
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
To resolve this : Expected: is "First is $1.00 (USD) which is $15,48 (Argentine Peso)" but: was "First is $1.00 (USD) which is $ 15,48 (Argentine Peso)"
public static String getPriceConversionForRecord(HousingRecord record,
Function<Integer, String> priceConverter) {
NumberFormat usFormatter = NumberFormat.getCurrencyInstance(Locale.US);
return String.format("%s is %s (USD) which is %s",
record.getRegionName(),
usFormatter.format(record.getCurrentHomeValueIndex()),
priceConverter.apply(record.getCurrentHomeValueIndex())
).replaceAll("\u00a0", " ");