according to wikipedia[1], swedish krona should be rounded with 1.00 intervals.
How can this be achieved with moneta/jsr-354? I made a test with CHF, EUR and SEK. CHF is rounded correctly, EUR is no rounding, but SEK also shows no rounding.
import org.javamoney.moneta.CurrencyUnitBuilder;
import org.javamoney.moneta.Money;
import javax.money.CurrencyUnit;
import javax.money.Monetary;
import javax.money.MonetaryRounding;
import javax.money.RoundingQueryBuilder;
import javax.money.format.MonetaryFormats;
import java.util.Locale;
public class MonetaTest {
public static void main(String[] args) {
CurrencyUnit chf = CurrencyUnitBuilder.of("CHF","").build();
CurrencyUnit eur = CurrencyUnitBuilder.of("EUR","").build();
CurrencyUnit sek = CurrencyUnitBuilder.of("SEK","").build();
MonetaryRounding rounding = Monetary.getRounding(
RoundingQueryBuilder.of()
.setCurrency(chf)
.set("cashRounding", true).build());
MonetaryRounding roundingEUR = Monetary.getRounding(
RoundingQueryBuilder.of()
.setCurrency(eur)
.set("cashRounding", true).build());
MonetaryRounding roundingSEK = Monetary.getRounding(
RoundingQueryBuilder.of()
.setCurrency(sek)
.set("cashRounding", true).build());
System.out.println(MonetaryFormats.getAmountFormat(new Locale("ch", "")).format(Money.of(3459.97,chf)));
System.out.println(MonetaryFormats.getAmountFormat(new Locale("ch", "")).format(Money.of(3459.97,chf).with(rounding)));
System.out.println(MonetaryFormats.getAmountFormat(new Locale("de", "")).format(Money.of(3459.97,eur)));
System.out.println(MonetaryFormats.getAmountFormat(new Locale("de", "")).format(Money.of(3459.97,eur).with(roundingEUR)));
System.out.println(MonetaryFormats.getAmountFormat(new Locale("sv", "")).format(Money.of(3459.97,sek)));
System.out.println(MonetaryFormats.getAmountFormat(new Locale("sv", "")).format(Money.of(3459.97,sek).with(roundingSEK)));
}
}
CHF 3,459.97
CHF 3,459.95
EUR 3.459,97
EUR 3.459,97
SEK 3 459,97
SEK 3 459,97