package com.firstrowria.formatters { public class OddFormatter { public static const EU_FORMAT:uint = 0; public static const US_FORMAT:uint = 1; public static const UK_FORMAT:uint = 2; public static function format(value:Number, oddFormat:uint = 0, commaChar:String = ",", precision:int = 2):String { var formattedValue:String = ""; if (oddFormat == UK_FORMAT) { var hundretValue:Number = Math.round(value * 100) - 100; var ggt:int = ggt(hundretValue, 100); formattedValue = (hundretValue / ggt) + "/" + (100 / ggt); } else if (oddFormat == US_FORMAT) { if (value >= 2) formattedValue = "+" + Math.round(100 * (value - 1)); else if (value == 1) formattedValue = "-0"; else formattedValue = "" + Math.round(100 / (1 - value)); } else if (oddFormat == EU_FORMAT) { formattedValue = value.toFixed(precision) if (commaChar != ".") formattedValue = formattedValue.replace(".", commaChar); } return formattedValue; } private static function ggt(u:int, v:int):int { return ((u > 0) ? ggt(v % u, u) : v); } } }