summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-05-21 18:50:19 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-05-21 18:50:19 +0200
commit57baa307c4404fe9017d8242317228e138f5b0dd (patch)
tree1798d0b8d43fc61bde65890e45e720549217a3d5
parentceff486ce21eca34a8ce8a6ecb7cc3150b206851 (diff)
Comments
-rw-r--r--format.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/format.go b/format.go
index 3a4f21b..f9e689d 100644
--- a/format.go
+++ b/format.go
@@ -25,16 +25,17 @@ func fill(s string, n int) string {
return s + strings.Repeat("0", n-len(s))
}
+// Country settings
type Country struct {
- Thousend, Decimal rune
- Block, Fraction int
+ Thousend, Decimal rune // delimiter rune
+ Block, Fraction int // block length
}
const (
- Space = '\u0020'
- Apostrophe = '\u0027'
- Comma = '\u002c'
- FullStop = '\u002e'
+ Space = ' '
+ Apostrophe = '\''
+ Comma = ','
+ FullStop = '.'
MiddleDot = '\u00b7'
ThinSpace = '\u2009'
NoBreakSpace = '\u202f'
@@ -49,11 +50,13 @@ var (
IR = Country{Space, MiddleDot, 3, 2}
CH = Country{Apostrophe, FullStop, 3, 2}
IT = Country{DotAbove, Comma, 3, 2}
- CN = Country{Comma, FullStop, 4, 2}
+ CN = Country{Comma, FullStop, 4, 2} // 10000 based
)
+// DefaultFormat is europeian SI format
var DefaultFormat = FR
+// Format float value as localized representation
func (c Country) Format(v float64) string {
s := strconv.FormatFloat(v, 'f', -1, 64)
neg := strings.HasPrefix(s, "-")