Package java.text

Examples of java.text.DecimalFormat


public CharSepTest(String name) {
    super(name);
}

public void setUp() throws Exception {
    dollarFormatter = new DecimalFormat("$#,###.00");
    lastColFormatter = new DecimalFormat("#,###.##");
    titleDateFormatter = new SimpleDateFormat(REPORT_DATE_FORMAT);

    report = new Report();
    reportRowNumber = officeRowNumber = postDateRowNumber = 1;
View Full Code Here


  //  ================== Format number TO String ==================
  public static String format(Number number, String format)
  throws FunctionExecutionException {
    try {
          DecimalFormat df = new DecimalFormat(format);
          return df.format(number);
    } catch (IllegalArgumentException iae) {
      throw new FunctionExecutionException("ERR.015.001.0042", QueryPlugin.Util.getString("ERR.015.001.0042" , //$NON-NLS-1$ //$NON-NLS-2$
      iae.getMessage()));
    }
  }
View Full Code Here

  // ============== Helper Function for format/parse numbers ==================

  private static Number parseNumberHelper(String number, String format)
    throws FunctionExecutionException {
    DecimalFormat df= new DecimalFormat(format);
    try {
      return df.parse(number);
    } catch (ParseException e) {
      throw new FunctionExecutionException("ERR.015.001.0043", QueryPlugin.Util.getString("ERR.015.001.0043" , //$NON-NLS-1$ //$NON-NLS-2$
          number,format));
    }
  }
View Full Code Here

         * Determine KB, MB, or GB for email size.
         */
        if (hm.get("size") != null)
        {
          float size = ((Integer)hm.get("size")).floatValue();
          DecimalFormat df = new DecimalFormat("###.#");
          Integer s = new Integer((int)size);
          String sizeStr = s.toString();
          if (size > 1000000000)
          {
            size /= 1073741824;          // 1GB
            sizeStr = df.format(size) + "GB";
          } else if (size > 1000000) {
            size /= 1048576;            // 1MB
            sizeStr = df.format(size) + "MB";
          } else if (size > 1000) {
            size /= 1024;               // 1KB
            sizeStr = df.format(size) + "KB";
          }
          messageSize = new StringMember("Size", sizeStr, 10, "URL", 'T', false);
        }else{
          messageSize = new StringMember("Size", "1KB", 10, "URL", 'T', false);
        }
View Full Code Here

          throws IOException, ClassNotFoundException
  {
    final SimpleDateFormat dfmt = new SimpleDateFormat("");
    System.out.println(dfmt.toPattern());

    final DecimalFormat dcfmt = new DecimalFormat(DECIMALFORMAT_DEFAULT_PATTERN);
    System.out.println(dcfmt.toPattern());

    testSerialization(dfmt);
    testSerialization(dcfmt);
  }
View Full Code Here

   */
  public void setParameterFromObject(final Object o)
      throws ObjectFactoryException
  {
    super.setParameterFromObject(o);
    final DecimalFormat format = (DecimalFormat) o;
    //setParameter("localizedPattern", format.toLocalizedPattern());
    setParameter("pattern", format.toPattern());
  }
View Full Code Here

   *
   * @return The object.
   */
  public Object createObject()
  {
    final DecimalFormat format = (DecimalFormat) super.createObject();
    if (getParameter("pattern") != null)
    {
      format.applyPattern((String) getParameter("pattern"));
    }
//        if (getParameter("localizedPattern") != null) {
//            format.applyLocalizedPattern((String) getParameter("localizedPattern"));
//        }
    return format;
View Full Code Here

    if (Number.class.isAssignableFrom(parameterType))
    {
      try
      {
        final DecimalFormat decimalFormat = new DecimalFormat(formatString, new DecimalFormatSymbols(locale));
        decimalFormat.setParseBigDecimal(true);
        return decimalFormat;
      }
      catch (Exception e)
      {
        // well, seems that was not a number format then ...
View Full Code Here

    {
      final StandardCategoryItemLabelGenerator scilg;
      if (categoricalLabelDecimalFormat != null)
      {
        scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat,
            new DecimalFormat(categoricalLabelDecimalFormat));
      }
      else if (categoricalLabelDateFormat != null)
      {
        scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat,
            new SimpleDateFormat(categoricalLabelDateFormat));
      }
      else
      {
        scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, new DecimalFormat());
      }
      renderer.setBaseItemLabelGenerator(scilg);
    }
    renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible()));
    if (getItemLabelFont() != null)
    {
      renderer.setBaseItemLabelFont(getItemLabelFont());
    }

    if (categoricalItemLabelRotation != null)
    {
      final ItemLabelPosition orgPosItemLabelPos = renderer.getBasePositiveItemLabelPosition();
      if (orgPosItemLabelPos == null)
      {
        final ItemLabelPosition pos2 = new ItemLabelPosition
            (ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER,
                TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue());
        renderer.setBasePositiveItemLabelPosition(pos2);
      }
      else
      {
        final ItemLabelPosition pos2 = new ItemLabelPosition
            (orgPosItemLabelPos.getItemLabelAnchor(), orgPosItemLabelPos.getTextAnchor(),
                orgPosItemLabelPos.getRotationAnchor(), categoricalItemLabelRotation.doubleValue());
        renderer.setBasePositiveItemLabelPosition(pos2);
      }

      final ItemLabelPosition orgNegItemLabelPos = renderer.getBaseNegativeItemLabelPosition();
      if (orgNegItemLabelPos == null)
      {
        final ItemLabelPosition pos2 = new ItemLabelPosition
            (ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER,
                TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue());
        renderer.setBaseNegativeItemLabelPosition(pos2);
      }
      else
      {
        final ItemLabelPosition neg2 = new ItemLabelPosition
            (orgNegItemLabelPos.getItemLabelAnchor(), orgNegItemLabelPos.getTextAnchor(),
                orgNegItemLabelPos.getRotationAnchor(), categoricalItemLabelRotation.doubleValue());
        renderer.setBaseNegativeItemLabelPosition(neg2);
      }
    }

    final Font labelFont = Font.decode(getLabelFont());


    final CategoryAxis categoryAxis = cpl.getDomainAxis();
    categoryAxis.setLabelFont(labelFont);
    categoryAxis.setTickLabelFont(labelFont);
    if (getCategoryTitleFont() != null)
    {
      categoryAxis.setLabelFont(getCategoryTitleFont());
    }
    if (getCategoryTickFont() != null)
    {
      categoryAxis.setTickLabelFont(getCategoryTickFont());
    }

    if (maxCategoryLabelWidthRatio != null)
    {
      categoryAxis.setMaximumCategoryLabelWidthRatio(maxCategoryLabelWidthRatio.floatValue());
    }
    cpl.setDomainGridlinesVisible(showGridlines);
    if (labelRotation != null)
    {
      categoryAxis.setCategoryLabelPositions
          (CategoryLabelPositions.createUpRotationLabelPositions(labelRotation.doubleValue()));
    }

    final String[] colors = getSeriesColor();
    for (int i = 0; i < colors.length; i++)
    {
      renderer.setSeriesPaint(i, parseColorFromString(colors[i]));
    }

    if (lowerMargin != null)
    {
      categoryAxis.setLowerMargin(lowerMargin.doubleValue());
    }
    if (upperMargin != null)
    {
      categoryAxis.setUpperMargin(upperMargin.doubleValue());
    }
    if (categoryMargin != null)
    {
      categoryAxis.setCategoryMargin(categoryMargin.doubleValue());
    }


    final ValueAxis rangeAxis = cpl.getRangeAxis();
    if (rangeAxis instanceof NumberAxis)
    {
      final NumberAxis numberAxis = (NumberAxis) rangeAxis;

      if (getRangePeriodCount() > 0)
      {
        if (getRangeTickFormat() != null)
        {
          numberAxis.setTickUnit(new NumberTickUnit(getRangePeriodCount(), getRangeTickFormat()));
        }
        else if (getRangeTickFormatString() != null)
        {
          final FastDecimalFormat formatter = new FastDecimalFormat
              (getRangeTickFormatString(), getResourceBundleFactory().getLocale());
          numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount(), formatter));
        }
        else
        {
          numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount()));
        }
      }
      else
      {
        if (getRangeTickFormat() != null)
        {
          numberAxis.setNumberFormatOverride(getRangeTickFormat());
        }
        else if (getRangeTickFormatString() != null)
        {
          final DecimalFormat formatter = new DecimalFormat
              (getRangeTickFormatString(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
          numberAxis.setNumberFormatOverride(formatter);
        }
      }
    }
View Full Code Here

     * 14 18 22 -2
    
     */
    protected void parseDataFromStream(String line) {
        StringTokenizer tokenizer = new StringTokenizer(line);
        DecimalFormat dec_format = new DecimalFormat();

        try {

            for (int i = 0; i < 2; i++)
                tokenizer.nextToken();
            /*int site_number = */dec_format.parse(tokenizer.nextToken())
                    .intValue();
            ;

            for (int i = 0; i < 2; i++)
                tokenizer.nextToken();
            float time = dec_format.parse(tokenizer.nextToken()).floatValue();

            float latitude = dec_format.parse(tokenizer.nextToken())
                    .floatValue();
            float longitude = dec_format.parse(tokenizer.nextToken())
                    .floatValue();

            tokenizer.nextToken(); // ignore Field 9

            float current_temp = dec_format.parse(tokenizer.nextToken())
                    .floatValue();

            //          float max_temp =
            //              dec_format.parse( tokenizer.nextToken() ).floatValue();
            //          float min_temp =
View Full Code Here

TOP

Related Classes of java.text.DecimalFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.