From 0e345e667540878680d7a423dda46a0d190e08fb Mon Sep 17 00:00:00 2001 From: bdew Date: Thu, 5 Feb 2015 00:52:42 +0200 Subject: [PATCH] Added DecFormat.short --- src/net/bdew/lib/DecFormat.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/net/bdew/lib/DecFormat.scala b/src/net/bdew/lib/DecFormat.scala index a2079b0..76a7fcc 100644 --- a/src/net/bdew/lib/DecFormat.scala +++ b/src/net/bdew/lib/DecFormat.scala @@ -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) }