From 031f68d7ed34a1ef3e1f6ef4170ac2a0997fa163 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 9 Oct 2008 02:02:39 +0200 Subject: [PATCH] Add method to format numbers. --- src/de/todesbaum/jsite/gui/ProjectInsertPage.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/de/todesbaum/jsite/gui/ProjectInsertPage.java b/src/de/todesbaum/jsite/gui/ProjectInsertPage.java index 6c3654f..7a3ccac 100644 --- a/src/de/todesbaum/jsite/gui/ProjectInsertPage.java +++ b/src/de/todesbaum/jsite/gui/ProjectInsertPage.java @@ -338,6 +338,28 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl clipboard.setContents(new StringSelection(requestURITextField.getText()), this); } + /** + * Formats the given number so that it always has the the given number of + * fractional digits. + * + * @param number + * The number to format + * @param digits + * The number of fractional digits + * @return The formatted number + */ + private String formatNumber(double number, int digits) { + int multiplier = (int) Math.pow(10, digits); + String formattedNumber = String.valueOf((int) (number * multiplier) / (double) multiplier); + if (formattedNumber.indexOf('.') == -1) { + formattedNumber += '.'; + for (int digit = 0; digit < digits; digit++) { + formattedNumber += "0"; + } + } + return formattedNumber; + } + // // INTERFACE ClipboardOwner // -- 2.7.4