currency: fixed bug related to rounding info

If Cash info isn't present, the values should default to the values
for standard, not to the global default.

The tables generated for this fix were accidentally already checked
in with the previous CL.

Change-Id: I1e8467bcb9bf506b755112d9574cdce5f131c680
Reviewed-on: https://go-review.googlesource.com/15880
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/currency/currency_test.go b/currency/currency_test.go
index 233be88..95da34c 100644
--- a/currency/currency_test.go
+++ b/currency/currency_test.go
@@ -124,6 +124,8 @@
 		{Cash, czk, 0, 1},
 		{Standard, zwr, 2, 1},
 		{Cash, zwr, 0, 1},
+		{Standard, KRW, 0, 1},
+		{Cash, KRW, 0, 1}, // Cash defaults to standard.
 	}
 	for i, tc := range testCases {
 		if scale, inc := tc.kind.Rounding(tc.cur); scale != tc.scale && inc != tc.inc {
diff --git a/currency/format_test.go b/currency/format_test.go
index 2567898..dc532d8 100644
--- a/currency/format_test.go
+++ b/currency/format_test.go
@@ -46,14 +46,15 @@
 		13: {en, 13.123, Symbol.Default(czk).Kind(Cash), "CZK 13"},
 		14: {en, 14.12345, ISO.Default(MustParseISO("CLF")), "CLF 14.1235"},
 		15: {en, USD.Value(15.00), ISO.Default(TWD), "USD 15.00"},
+		16: {en, KRW.Value(16.00), ISO.Kind(Cash), "KRW 16"},
 
 		// TODO: support integers as well.
 
-		16: {en, USD, nil, "USD"},
-		17: {en, USD, ISO, "USD"},
-		18: {en, USD, Symbol, "$"},
-		19: {en_AU, USD, Symbol, "US$"},
-		20: {en_AU, USD, NarrowSymbol, "$"},
+		17: {en, USD, nil, "USD"},
+		18: {en, USD, ISO, "USD"},
+		19: {en, USD, Symbol, "$"},
+		20: {en_AU, USD, Symbol, "US$"},
+		21: {en_AU, USD, NarrowSymbol, "$"},
 	}
 	for i, tc := range testCases {
 		p := message.NewPrinter(tc.tag)
diff --git a/currency/gen.go b/currency/gen.go
index 23e1dee..c7d25dc 100644
--- a/currency/gen.go
+++ b/currency/gen.go
@@ -137,8 +137,8 @@
 		if info.Iso4217 == "DEFAULT" {
 			continue
 		}
-		standard := getRoundingIndex(info.Digits, info.Rounding)
-		cash := getRoundingIndex(info.CashDigits, info.CashRounding)
+		standard := getRoundingIndex(info.Digits, info.Rounding, 0)
+		cash := getRoundingIndex(info.CashDigits, info.CashRounding, standard)
 
 		index := sort.SearchStrings(currencies, info.Iso4217)
 		currencies[index] += mkCurrencyInfo(standard, cash)
@@ -203,8 +203,8 @@
 	return string([]byte{byte(cash<<cashShift | standard)})
 }
 
-func getRoundingIndex(digits, rounding string) int {
-	round := roundings[0] // default
+func getRoundingIndex(digits, rounding string, defIndex int) int {
+	round := roundings[defIndex] // default
 
 	if digits != "" {
 		round.scale = parseUint8(digits)