From: David ‘Bombe’ Roden Date: Thu, 9 Oct 2008 00:02:39 +0000 (+0200) Subject: Add method to format numbers. X-Git-Tag: 0.6.1~3 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=031f68d7ed34a1ef3e1f6ef4170ac2a0997fa163;p=jSite.git Add method to format numbers. --- 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 //