mirror of
https://github.com/pbnjay/grate.git
synced 2024-12-12 13:35:18 +02:00
fix th-th formats and fractions w/no whole part
This commit is contained in:
parent
10c14fa766
commit
7570bd9134
@ -149,6 +149,12 @@ func fracFmtFunc(n int) FmtFunc {
|
||||
if n == 0 {
|
||||
return fmt.Sprintf("%d", w)
|
||||
}
|
||||
if w == 0 {
|
||||
if f < 0 && n > 0 {
|
||||
n = -n
|
||||
}
|
||||
return fmt.Sprintf("%d/%d", n, d)
|
||||
}
|
||||
return fmt.Sprintf("%d %d/%d", w, n, d)
|
||||
}
|
||||
}
|
||||
@ -235,26 +241,26 @@ var goFormatters = map[uint16]FmtFunc{
|
||||
12: fracFmtFunc(1),
|
||||
13: fracFmtFunc(2),
|
||||
|
||||
69: surround("t", fracFmtFunc(1), ""),
|
||||
70: surround("t", fracFmtFunc(2), ""),
|
||||
69: fracFmtFunc(1),
|
||||
70: fracFmtFunc(2),
|
||||
|
||||
1: sprintfFunc(`%d`, 1),
|
||||
2: sprintfFunc(`%4.2f`, 1),
|
||||
59: sprintfFunc(`t%d`, 1),
|
||||
60: sprintfFunc(`t%4.2f`, 1),
|
||||
59: sprintfFunc(`%d`, 1),
|
||||
60: sprintfFunc(`%4.2f`, 1),
|
||||
|
||||
9: sprintfFunc(`%d%%`, 100),
|
||||
10: sprintfFunc(`%4.2f%%`, 100),
|
||||
67: sprintfFunc(`t%d%%`, 100),
|
||||
68: sprintfFunc(`t%4.2f%%`, 100),
|
||||
67: sprintfFunc(`%d%%`, 100),
|
||||
68: sprintfFunc(`%4.2f%%`, 100),
|
||||
|
||||
3: addCommas(sprintfFunc("%d", 1)),
|
||||
61: surround("t", addCommas(sprintfFunc("%d", 1)), ""),
|
||||
61: addCommas(sprintfFunc("%d", 1)),
|
||||
37: addNegParens(addCommas(sprintfFunc("%d", 1))),
|
||||
38: addNegParens(addCommas(sprintfFunc("%d", 1))),
|
||||
|
||||
4: addCommas(sprintfFunc("%4.2f", 1)),
|
||||
62: surround("t", addCommas(sprintfFunc("%4.2f", 1)), ""),
|
||||
62: addCommas(sprintfFunc("%4.2f", 1)),
|
||||
39: addNegParens(addCommas(sprintfFunc("%4.2f", 1))),
|
||||
40: addNegParens(addCommas(sprintfFunc("%4.2f", 1))),
|
||||
|
||||
|
@ -282,15 +282,16 @@ var builtInFormats = map[uint16]string{
|
||||
57: `yyyy"年"m"月"`,
|
||||
58: `m"月"d"日"`,
|
||||
|
||||
// th-th format codes
|
||||
59: `t0`,
|
||||
60: `t0.00`,
|
||||
61: `t#,##0`,
|
||||
62: `t#,##0.00`,
|
||||
67: `t0%`,
|
||||
68: `t0.00%`,
|
||||
69: `t# ?/?`,
|
||||
70: `t# ??/??`,
|
||||
// th-th format codes (in the spec these have a "t" prefix?)
|
||||
59: `0`,
|
||||
60: `0.00`,
|
||||
61: `#,##0`,
|
||||
62: `#,##0.00`,
|
||||
67: `0%`,
|
||||
68: `0.00%`,
|
||||
69: `# ?/?`,
|
||||
70: `# ??/??`,
|
||||
|
||||
// th format code, but translated to aid the parser
|
||||
71: `d/m/yyyy`, // `ว/ด/ปปปป`,
|
||||
72: `d-mmm-yy`, // `ว-ดดด-ปป`,
|
||||
|
@ -12,6 +12,11 @@ type testcaseFrac struct {
|
||||
}
|
||||
|
||||
var fracs = []testcaseFrac{
|
||||
{0, "0", 1},
|
||||
{0.5, "1/2", 1},
|
||||
{-0.5, "-1/2", 1},
|
||||
{0.125, "1/8", 1},
|
||||
|
||||
{10, "10", 1},
|
||||
{-10, "-10", 1},
|
||||
{10.5, "10 1/2", 1},
|
||||
|
Loading…
Reference in New Issue
Block a user