List of usage examples for java.text DecimalFormatSymbols DecimalFormatSymbols
public DecimalFormatSymbols(Locale locale)
From source file:org.pentaho.di.trans.steps.script.ScriptAddedFunctions.java
public static String num2str(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext) { String sRC = ""; switch (ArgList.length) { case 0:/*from w w w .jav a 2s . co m*/ throw new RuntimeException("The function call num2str requires at least 1 argument."); case 1: try { if (isNull(ArgList[0])) { return null; } else if (isUndefined(ArgList[0])) { return (String) undefinedValue; } double sArg1 = (Double) ArgList[0]; if (Double.isNaN(sArg1)) { throw new RuntimeException("The first Argument must be a Number."); } DecimalFormat formatter = new DecimalFormat(); sRC = formatter.format(sArg1); } catch (IllegalArgumentException e) { throw new RuntimeException("Could not apply the given format on the number : " + e.getMessage()); } break; case 2: try { if (isNull(ArgList, new int[] { 0, 1 })) { return null; } else if (isUndefined(ArgList, new int[] { 0, 1 })) { return (String) undefinedValue; } double sArg1 = (Double) ArgList[0]; if (Double.isNaN(sArg1)) { throw new RuntimeException("The first Argument must be a Number."); } String sArg2 = (String) ArgList[1]; DecimalFormat formatter = new DecimalFormat(sArg2); sRC = formatter.format(sArg1); } catch (IllegalArgumentException e) { throw new RuntimeException("Could not apply the given format on the number : " + e.getMessage()); } break; case 3: try { if (isNull(ArgList, new int[] { 0, 1, 2 })) { return null; } else if (isUndefined(ArgList, new int[] { 0, 1, 2 })) { return (String) undefinedValue; } double sArg1 = (Double) ArgList[0]; if (Double.isNaN(sArg1)) { throw new RuntimeException("The first Argument must be a Number."); } String sArg2 = (String) ArgList[1]; String sArg3 = (String) ArgList[2]; if (sArg3.length() == 2) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(EnvUtil.createLocale(sArg3.toLowerCase())); DecimalFormat formatter = new DecimalFormat(sArg2, dfs); sRC = formatter.format(sArg1); } } catch (Exception e) { throw new RuntimeException(e.toString()); } break; default: throw new RuntimeException("The function call num2str requires 1, 2, or 3 arguments."); } return sRC; }
From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static String num2str(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { String sRC = ""; switch (ArgList.length) { case 0://from w w w. j ava 2 s . c o m throw Context.reportRuntimeError("The function call num2str requires at least 1 argument."); case 1: try { if (isNull(ArgList[0])) return null; else if (isUndefined(ArgList[0])) return (String) Context.getUndefinedValue(); double sArg1 = Context.toNumber(ArgList[0]); if (Double.isNaN(sArg1)) throw Context.reportRuntimeError("The first Argument must be a Number."); DecimalFormat formatter = new DecimalFormat(); sRC = formatter.format(sArg1); } catch (IllegalArgumentException e) { throw Context .reportRuntimeError("Could not apply the given format on the number : " + e.getMessage()); } break; case 2: try { if (isNull(ArgList, new int[] { 0, 1 })) return null; else if (isUndefined(ArgList, new int[] { 0, 1 })) return (String) Context.getUndefinedValue(); double sArg1 = Context.toNumber(ArgList[0]); if (Double.isNaN(sArg1)) throw Context.reportRuntimeError("The first Argument must be a Number."); String sArg2 = Context.toString(ArgList[1]); DecimalFormat formatter = new DecimalFormat(sArg2); sRC = formatter.format(sArg1); } catch (IllegalArgumentException e) { throw Context .reportRuntimeError("Could not apply the given format on the number : " + e.getMessage()); } break; case 3: try { if (isNull(ArgList, new int[] { 0, 1, 2 })) return null; else if (isUndefined(ArgList, new int[] { 0, 1, 2 })) return (String) Context.getUndefinedValue(); double sArg1 = Context.toNumber(ArgList[0]); if (Double.isNaN(sArg1)) throw Context.reportRuntimeError("The first Argument must be a Number."); String sArg2 = Context.toString(ArgList[1]); String sArg3 = Context.toString(ArgList[2]); if (sArg3.length() == 2) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(new Locale(sArg3.toLowerCase())); DecimalFormat formatter = new DecimalFormat(sArg2, dfs); sRC = formatter.format(sArg1); } } catch (Exception e) { throw Context.reportRuntimeError(e.toString()); } break; default: throw Context.reportRuntimeError("The function call num2str requires 1, 2, or 3 arguments."); } return sRC; }
From source file:com.akretion.kettle.steps.terminatooor.ScriptValuesAddedFunctions.java
public static Object str2num(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext) { double dRC = 0.00; switch (ArgList.length) { case 0://from w w w . j a v a 2s .co m throw new RuntimeException("The function call str2num requires at least 1 argument."); case 1: try { if (isNull(ArgList[0])) return new Double(Double.NaN); else if (isUndefined(ArgList[0])) return undefinedValue; if (ArgList[0].equals(null)) return null; String sArg1 = (String) ArgList[0]; DecimalFormat formatter = new DecimalFormat(); dRC = (formatter.parse(Const.ltrim(sArg1))).doubleValue(); } catch (Exception e) { throw new RuntimeException("Could not convert the given String : " + e.getMessage()); } break; case 2: try { if (isNull(ArgList, new int[] { 0, 1 })) return new Double(Double.NaN); else if (isUndefined(ArgList, new int[] { 0, 1 })) return undefinedValue; String sArg1 = (String) ArgList[0]; String sArg2 = (String) ArgList[1]; if (sArg1.equals("null") || sArg2.equals("null")) return null; DecimalFormat formatter = new DecimalFormat(sArg2); dRC = (formatter.parse(sArg1)).doubleValue(); return new Double(dRC); } catch (Exception e) { throw new RuntimeException("Could not convert the String with the given format :" + e.getMessage()); } //break; case 3: try { if (isNull(ArgList, new int[] { 0, 1, 2 })) return new Double(Double.NaN); else if (isUndefined(ArgList, new int[] { 0, 1, 2 })) return undefinedValue; String sArg1 = (String) ArgList[0]; String sArg2 = (String) ArgList[1]; String sArg3 = (String) ArgList[2]; if (sArg3.length() == 2) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(new Locale(sArg3.toLowerCase())); DecimalFormat formatter = new DecimalFormat(sArg2, dfs); dRC = (formatter.parse(sArg1)).doubleValue(); return new Double(dRC); } } catch (Exception e) { throw new RuntimeException(e.getMessage()); } break; default: throw new RuntimeException("The function call str2num requires 1, 2, or 3 arguments."); } return new Double(dRC); }
From source file:org.pentaho.di.trans.steps.script.ScriptAddedFunctions.java
public static Object str2num(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext) { double dRC = 0.00; switch (ArgList.length) { case 0:/* ww w . ja va 2 s . c o m*/ throw new RuntimeException("The function call str2num requires at least 1 argument."); case 1: try { if (isNull(ArgList[0])) { return new Double(Double.NaN); } else if (isUndefined(ArgList[0])) { return undefinedValue; } if (ArgList[0].equals(null)) { return null; } String sArg1 = (String) ArgList[0]; DecimalFormat formatter = new DecimalFormat(); dRC = (formatter.parse(Const.ltrim(sArg1))).doubleValue(); } catch (Exception e) { throw new RuntimeException("Could not convert the given String : " + e.getMessage()); } break; case 2: try { if (isNull(ArgList, new int[] { 0, 1 })) { return new Double(Double.NaN); } else if (isUndefined(ArgList, new int[] { 0, 1 })) { return undefinedValue; } String sArg1 = (String) ArgList[0]; String sArg2 = (String) ArgList[1]; if (sArg1.equals("null") || sArg2.equals("null")) { return null; } DecimalFormat formatter = new DecimalFormat(sArg2); dRC = (formatter.parse(sArg1)).doubleValue(); return new Double(dRC); } catch (Exception e) { throw new RuntimeException("Could not convert the String with the given format :" + e.getMessage()); } // break; case 3: try { if (isNull(ArgList, new int[] { 0, 1, 2 })) { return new Double(Double.NaN); } else if (isUndefined(ArgList, new int[] { 0, 1, 2 })) { return undefinedValue; } String sArg1 = (String) ArgList[0]; String sArg2 = (String) ArgList[1]; String sArg3 = (String) ArgList[2]; if (sArg3.length() == 2) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(EnvUtil.createLocale(sArg3.toLowerCase())); DecimalFormat formatter = new DecimalFormat(sArg2, dfs); dRC = (formatter.parse(sArg1)).doubleValue(); return new Double(dRC); } } catch (Exception e) { throw new RuntimeException(e.getMessage()); } break; default: throw new RuntimeException("The function call str2num requires 1, 2, or 3 arguments."); } return new Double(dRC); }
From source file:org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static String num2str(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { String sRC = ""; switch (ArgList.length) { case 0:/* ww w .ja v a2 s. c o m*/ throw Context.reportRuntimeError("The function call num2str requires at least 1 argument."); case 1: try { if (isNull(ArgList[0])) { return null; } else if (isUndefined(ArgList[0])) { return (String) Context.getUndefinedValue(); } double sArg1 = Context.toNumber(ArgList[0]); if (Double.isNaN(sArg1)) { throw Context.reportRuntimeError("The first Argument must be a Number."); } DecimalFormat formatter = new DecimalFormat(); sRC = formatter.format(sArg1); } catch (IllegalArgumentException e) { throw Context .reportRuntimeError("Could not apply the given format on the number : " + e.getMessage()); } break; case 2: try { if (isNull(ArgList, new int[] { 0, 1 })) { return null; } else if (isUndefined(ArgList, new int[] { 0, 1 })) { return (String) Context.getUndefinedValue(); } double sArg1 = Context.toNumber(ArgList[0]); if (Double.isNaN(sArg1)) { throw Context.reportRuntimeError("The first Argument must be a Number."); } String sArg2 = Context.toString(ArgList[1]); DecimalFormat formatter = new DecimalFormat(sArg2); sRC = formatter.format(sArg1); } catch (IllegalArgumentException e) { throw Context .reportRuntimeError("Could not apply the given format on the number : " + e.getMessage()); } break; case 3: try { if (isNull(ArgList, new int[] { 0, 1, 2 })) { return null; } else if (isUndefined(ArgList, new int[] { 0, 1, 2 })) { return (String) Context.getUndefinedValue(); } double sArg1 = Context.toNumber(ArgList[0]); if (Double.isNaN(sArg1)) { throw Context.reportRuntimeError("The first Argument must be a Number."); } String sArg2 = Context.toString(ArgList[1]); String sArg3 = Context.toString(ArgList[2]); if (sArg3.length() == 2) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(EnvUtil.createLocale(sArg3.toLowerCase())); DecimalFormat formatter = new DecimalFormat(sArg2, dfs); sRC = formatter.format(sArg1); } } catch (Exception e) { throw Context.reportRuntimeError(e.toString()); } break; default: throw Context.reportRuntimeError("The function call num2str requires 1, 2, or 3 arguments."); } return sRC; }
From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static Object str2num(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { double dRC = 0.00; switch (ArgList.length) { case 0://ww w . j a va 2s . co m throw Context.reportRuntimeError("The function call str2num requires at least 1 argument."); case 1: try { if (isNull(ArgList[0])) return new Double(Double.NaN); else if (isUndefined(ArgList[0])) return Context.getUndefinedValue(); if (ArgList[0].equals(null)) return null; String sArg1 = Context.toString(ArgList[0]); DecimalFormat formatter = new DecimalFormat(); dRC = (formatter.parse(Const.ltrim(sArg1))).doubleValue(); } catch (Exception e) { throw Context.reportRuntimeError("Could not convert the given String : " + e.getMessage()); } break; case 2: try { if (isNull(ArgList, new int[] { 0, 1 })) return new Double(Double.NaN); else if (isUndefined(ArgList, new int[] { 0, 1 })) return Context.getUndefinedValue(); String sArg1 = Context.toString(ArgList[0]); String sArg2 = Context.toString(ArgList[1]); if (sArg1.equals("null") || sArg2.equals("null")) return null; DecimalFormat formatter = new DecimalFormat(sArg2); dRC = (formatter.parse(sArg1)).doubleValue(); return new Double(dRC); } catch (Exception e) { throw Context.reportRuntimeError( "Could not convert the String with the given format :" + e.getMessage()); } //break; case 3: try { if (isNull(ArgList, new int[] { 0, 1, 2 })) return new Double(Double.NaN); else if (isUndefined(ArgList, new int[] { 0, 1, 2 })) return Context.getUndefinedValue(); String sArg1 = Context.toString(ArgList[0]); String sArg2 = Context.toString(ArgList[1]); String sArg3 = Context.toString(ArgList[2]); if (sArg3.length() == 2) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(new Locale(sArg3.toLowerCase())); DecimalFormat formatter = new DecimalFormat(sArg2, dfs); dRC = (formatter.parse(sArg1)).doubleValue(); return new Double(dRC); } } catch (Exception e) { throw Context.reportRuntimeError(e.getMessage()); } break; default: throw Context.reportRuntimeError("The function call str2num requires 1, 2, or 3 arguments."); } return new Double(dRC); }
From source file:org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static Object str2num(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { double dRC = 0.00; switch (ArgList.length) { case 0:/* www .java 2 s . c om*/ throw Context.reportRuntimeError("The function call str2num requires at least 1 argument."); case 1: try { if (isNull(ArgList[0])) { return new Double(Double.NaN); } else if (isUndefined(ArgList[0])) { return Context.getUndefinedValue(); } if (ArgList[0].equals(null)) { return null; } String sArg1 = Context.toString(ArgList[0]); DecimalFormat formatter = new DecimalFormat(); dRC = (formatter.parse(Const.ltrim(sArg1))).doubleValue(); } catch (Exception e) { throw Context.reportRuntimeError("Could not convert the given String : " + e.getMessage()); } break; case 2: try { if (isNull(ArgList, new int[] { 0, 1 })) { return new Double(Double.NaN); } else if (isUndefined(ArgList, new int[] { 0, 1 })) { return Context.getUndefinedValue(); } String sArg1 = Context.toString(ArgList[0]); String sArg2 = Context.toString(ArgList[1]); if (sArg1.equals("null") || sArg2.equals("null")) { return null; } DecimalFormat formatter = new DecimalFormat(sArg2); dRC = (formatter.parse(sArg1)).doubleValue(); return new Double(dRC); } catch (Exception e) { throw Context.reportRuntimeError( "Could not convert the String with the given format :" + e.getMessage()); } // break; case 3: try { if (isNull(ArgList, new int[] { 0, 1, 2 })) { return new Double(Double.NaN); } else if (isUndefined(ArgList, new int[] { 0, 1, 2 })) { return Context.getUndefinedValue(); } String sArg1 = Context.toString(ArgList[0]); String sArg2 = Context.toString(ArgList[1]); String sArg3 = Context.toString(ArgList[2]); if (sArg3.length() == 2) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(EnvUtil.createLocale(sArg3.toLowerCase())); DecimalFormat formatter = new DecimalFormat(sArg2, dfs); dRC = (formatter.parse(sArg1)).doubleValue(); return new Double(dRC); } } catch (Exception e) { throw Context.reportRuntimeError(e.getMessage()); } break; default: throw Context.reportRuntimeError("The function call str2num requires 1, 2, or 3 arguments."); } return new Double(dRC); }
From source file:de.innovationgate.wga.server.api.WGA.java
/** * Returns an OpenWGA number format//from w w w . jav a 2 s. c o m * @param pattern The number format pattern * @param locale A locale to use for locale-dependent number parts. Specify null to let the current WebTML context choose the locale. * @throws WGException */ public NumberFormat getNumberFormat(String pattern, Locale locale) throws WGException { // Select language for language dependent number formats if (locale == null) { locale = chooseLocale(locale); } if (WGUtils.isEmpty(pattern)) { NumberFormat numberFormat = NumberFormat.getNumberInstance(locale); numberFormat.setMaximumFractionDigits(Integer.MAX_VALUE); numberFormat.setMaximumIntegerDigits(Integer.MAX_VALUE); return numberFormat; } // For default pattern if (pattern.toLowerCase().equals("decimal")) { return NumberFormat.getNumberInstance(locale); } // Custom pattern return new DecimalFormat(pattern, new DecimalFormatSymbols(locale)); }