List of usage examples for java.text DecimalFormatSymbols DecimalFormatSymbols
public DecimalFormatSymbols(Locale locale)
From source file:DecimalFormatDemo.java
static public void main(String[] args) { customFormat("###,###.###", 123456.789); customFormat("###.##", 123456.789); customFormat("000000.000", 123.78); customFormat("$###,###.###", 12345.67); customFormat("\u00a5###,###.###", 12345.67); Locale currentLocale = new Locale("en", "US"); DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols(currentLocale); unusualSymbols.setDecimalSeparator('|'); unusualSymbols.setGroupingSeparator('^'); String strange = "#,##0.###"; DecimalFormat weirdFormatter = new DecimalFormat(strange, unusualSymbols); weirdFormatter.setGroupingSize(4);/* w w w.j av a2 s .c om*/ String bizarre = weirdFormatter.format(12345.678); System.out.println(bizarre); Locale[] locales = { new Locale("en", "US"), new Locale("de", "DE"), new Locale("fr", "FR") }; for (int i = 0; i < locales.length; i++) { localizedFormat("###,###.###", 123456.789, locales[i]); } }
From source file:fr.cs.examples.attitude.EarthObservation.java
/** Program entry point. * @param args program arguments (unused here) *///from ww w. jav a2 s .c o m public static void main(String[] args) { try { // configure Orekit Autoconfiguration.configureOrekit(); final SortedSet<String> output = new TreeSet<String>(); // Initial state definition : date, orbit final AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, TimeScalesFactory.getUTC()); final Vector3D position = new Vector3D(-6142438.668, 3492467.560, -25767.25680); final Vector3D velocity = new Vector3D(505.8479685, 942.7809215, 7435.922231); final Orbit initialOrbit = new KeplerianOrbit(new PVCoordinates(position, velocity), FramesFactory.getEME2000(), initialDate, Constants.EIGEN5C_EARTH_MU); // Attitudes sequence definition final AttitudeProvider dayObservationLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, FastMath.toRadians(20), FastMath.toRadians(40), 0); final AttitudeProvider nightRestingLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH); final PVCoordinatesProvider sun = CelestialBodyFactory.getSun(); final PVCoordinatesProvider earth = CelestialBodyFactory.getEarth(); final EventDetector dayNightEvent = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new ContinueOnEvent<EclipseDetector>()); final EventDetector nightDayEvent = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new ContinueOnEvent<EclipseDetector>()); final AttitudesSequence attitudesSequence = new AttitudesSequence(); final AttitudesSequence.SwitchHandler switchHandler = new AttitudesSequence.SwitchHandler() { public void switchOccurred(AttitudeProvider preceding, AttitudeProvider following, SpacecraftState s) { if (preceding == dayObservationLaw) { output.add(s.getDate() + ": switching to night law"); } else { output.add(s.getDate() + ": switching to day law"); } } }; attitudesSequence.addSwitchingCondition(dayObservationLaw, nightRestingLaw, dayNightEvent, false, true, 10.0, AngularDerivativesFilter.USE_R, switchHandler); attitudesSequence.addSwitchingCondition(nightRestingLaw, dayObservationLaw, nightDayEvent, true, false, 10.0, AngularDerivativesFilter.USE_R, switchHandler); if (dayNightEvent.g(new SpacecraftState(initialOrbit)) >= 0) { // initial position is in daytime attitudesSequence.resetActiveProvider(dayObservationLaw); } else { // initial position is in nighttime attitudesSequence.resetActiveProvider(nightRestingLaw); } // Propagator : consider the analytical Eckstein-Hechler model final Propagator propagator = new EcksteinHechlerPropagator(initialOrbit, attitudesSequence, Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS, Constants.EIGEN5C_EARTH_MU, Constants.EIGEN5C_EARTH_C20, Constants.EIGEN5C_EARTH_C30, Constants.EIGEN5C_EARTH_C40, Constants.EIGEN5C_EARTH_C50, Constants.EIGEN5C_EARTH_C60); // Register the switching events to the propagator attitudesSequence.registerSwitchEvents(propagator); propagator.setMasterMode(180.0, new OrekitFixedStepHandler() { public void init(final SpacecraftState s0, final AbsoluteDate t) { } public void handleStep(SpacecraftState currentState, boolean isLast) throws PropagationException { try { DecimalFormatSymbols angleDegree = new DecimalFormatSymbols(Locale.US); angleDegree.setDecimalSeparator('\u00b0'); DecimalFormat ad = new DecimalFormat(" 00.000;-00.000", angleDegree); // the Earth position in spacecraft frame should be along spacecraft Z axis // during nigthtime and away from it during daytime due to roll and pitch offsets final Vector3D earth = currentState.toTransform().transformPosition(Vector3D.ZERO); final double pointingOffset = Vector3D.angle(earth, Vector3D.PLUS_K); // the g function is the eclipse indicator, its an angle between Sun and Earth limb, // positive when Sun is outside of Earth limb, negative when Sun is hidden by Earth limb final double eclipseAngle = dayNightEvent.g(currentState); output.add(currentState.getDate() + " " + ad.format(FastMath.toDegrees(eclipseAngle)) + " " + ad.format(FastMath.toDegrees(pointingOffset))); } catch (OrekitException oe) { throw new PropagationException(oe); } } }); // Propagate from the initial date for the fixed duration SpacecraftState finalState = propagator.propagate(initialDate.shiftedBy(12600.)); // we print the lines according to lexicographic order, which is chronological order here // to make sure out of orders calls between step handler and event handlers don't mess things up for (final String line : output) { System.out.println(line); } System.out.println("Propagation ended at " + finalState.getDate()); } catch (OrekitException oe) { System.err.println(oe.getMessage()); } }
From source file:Main.java
public static char setDecimalSeparator(Locale locale) { DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale); return decimalFormatSymbols.getDecimalSeparator(); }
From source file:Main.java
protected static DecimalFormatSymbols getDecimalFormatSymbols(Locale locale) { DecimalFormatSymbols symbols = (DecimalFormatSymbols) symbolsCache.get(locale); if (symbols == null) { symbols = new DecimalFormatSymbols(locale); symbolsCache.put(locale, symbols); }/*from ww w .j a va 2 s. co m*/ return symbols; }
From source file:com.squarespace.template.plugins.platform.PlatformUtils.java
public static String formatPercentage(double percentage, boolean trim, Locale locale) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); String pattern = trim ? "#,##0.###" : "#,##0.00#"; DecimalFormat format = new DecimalFormat(pattern, symbols); return format.format(percentage); }
From source file:com.itude.mobile.mobbl.core.util.StringUtilities.java
private static void setupFormatter(DecimalFormat formatter, int minumumDecimals, int maximumDecimals) { formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(getDefaultFormattingLocale())); formatter.setMinimumIntegerDigits(1); if (minumumDecimals > -1) { formatter.setMinimumFractionDigits(minumumDecimals); }//from w w w.j a v a 2s . c o m if (maximumDecimals > -1) { formatter.setMaximumFractionDigits(maximumDecimals); } formatter.setGroupingUsed(true); formatter.setGroupingSize(3); }
From source file:org.webguitoolkit.ui.controls.util.validation.PositiveNumberValidator.java
public void validate(String object) throws ValidationException { try {/*from w w w .j a va 2 s .c om*/ // no mandatory field: empty means value zero. if (StringUtils.isEmpty(object)) { return; } else { DecimalFormat formatter; formatter = new DecimalFormat(pattern, new DecimalFormatSymbols(TextService.getLocale())); ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(object, pos); if (num == null) throw new ValidationException(TextService.getString( "converter.PositiveNumberValidator.message.conversion@Cannot convert into number.")); if (pos.getIndex() < object.length()) { throw new ValidationException(TextService.getString( "converter.PositiveNumberValidator.message.conversion@Cannot convert into number.")); } Double f = new Double(num.doubleValue()); if (f.doubleValue() < 0) { throw new ValidationException(TextService.getString( "validator.PositiveNumberValidator.message@The entered number must be positive.")); } } } catch (NumberFormatException e) { throw new ValidationException(TextService .getString("validator.PositiveNumberValidator.message.conversion@Cannot convert into number.")); } }
From source file:org.brickhouse.json.HNumberConverter.java
@Override public void jsonWrite(JsonWriter writer, Object value) throws IOException, JsonException { HNumber h = (HNumber) value;/* w ww . j a v a 2 s.c om*/ // Check if we can just write a number. if (StringUtils.isEmpty(h.getUnit()) && h != HNumber.NaN && h != HNumber.NEG_INF && h != HNumber.POS_INF) writer.append( (new DecimalFormat("#0.####", new DecimalFormatSymbols(Locale.ENGLISH))).format(h.getValue())); else { StringBuilder sb = new StringBuilder().append(CODE).append(HValueConverter.ESCAPE); if (Double.isNaN(h.getValue())) sb.append("NaN"); else if (h.getValue() == Double.NEGATIVE_INFINITY) sb.append("-INF"); else if (h.getValue() == Double.POSITIVE_INFINITY) sb.append("INF"); else sb.append((new DecimalFormat("#0.####", new DecimalFormatSymbols(Locale.ENGLISH))) .format(h.getValue())); if (!StringUtils.isEmpty(h.getUnit())) sb.append(h.getUnit()); writer.quote(sb.toString()); } }
From source file:thymeleafsandbox.springjsp.web.conversion.NumberFormatter.java
public Number parse(final String text, final Locale locale) throws ParseException { final DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getNumberInstance(); final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US); symbols.setGroupingSeparator('*'); numberFormat.setDecimalFormatSymbols(symbols); return numberFormat.parse(text); }
From source file:com.itude.mobile.android.util.StringUtil.java
/** * Set the formatter./* w w w.j a v a 2 s . c o m*/ * * @param formatter {@link DecimalFormat} * @param locale {@link Locale} * @param minimalDecimalNumbers minimal number of decimals * @param maximumDecimalNumbers maximum number of decimals */ private static void setupFormatter(DecimalFormat formatter, Locale locale, int minimalDecimalNumbers, int maximumDecimalNumbers) { formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(locale)); formatter.setMinimumIntegerDigits(1); formatter.setMinimumFractionDigits(minimalDecimalNumbers); formatter.setMaximumFractionDigits(maximumDecimalNumbers); formatter.setGroupingUsed(true); formatter.setGroupingSize(3); }