Added DecFormat.short

This commit is contained in:
bdew committed 2015-02-05 00:52:42 +02:00
1 parent e78e565ec8
commit 0e345e6675
1 file changed
+5
+5
View File
@@ -14,6 +14,7 @@ import java.text.DecimalFormat
object DecFormat {
val thousandsFmt = new DecimalFormat("#,##0")
val dec2Fmt = new DecimalFormat("#,##0.00")
val dec1Fmt = new DecimalFormat("#,##0.0")
def round(x: Double) = thousandsFmt.format(x)
def round(x: Float) = thousandsFmt.format(x)
@@ -22,4 +23,8 @@ object DecFormat {
def dec2(x: Double) = dec2Fmt.format(x)
def dec2(x: Float) = dec2Fmt.format(x)
def dec2(x: Int) = dec2Fmt.format(x)
def short(x: Double) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
def short(x: Float) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
def short(x: Int) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
}