コード例 #1
1
ファイル: Gadget.java プロジェクト: VenaCzPlay/UltraCosmetics
  /** Sends the current cooldown in action bar. */
  private void sendCooldownBar() {
    if (getPlayer() == null) return;

    StringBuilder stringBuilder = new StringBuilder();

    double currentCooldown = Core.getCustomPlayer(getPlayer()).canUse(type);
    double maxCooldown = type.getCountdown();

    int res = (int) (currentCooldown / maxCooldown * 10);
    ChatColor color;
    for (int i = 0; i < 10; i++) {
      color = ChatColor.RED;
      if (i < 10 - res) color = ChatColor.GREEN;
      stringBuilder.append(color + "â–�");
    }

    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
    otherSymbols.setDecimalSeparator('.');
    otherSymbols.setGroupingSeparator('.');
    otherSymbols.setPatternSeparator('.');
    final DecimalFormat decimalFormat = new DecimalFormat("0.0", otherSymbols);
    String timeLeft = decimalFormat.format(currentCooldown) + "s";

    PlayerUtils.sendInActionBar(
        getPlayer(), getName() + " §f" + stringBuilder.toString() + " §f" + timeLeft);
  }
コード例 #2
0
  /**
   * Metodo para formatear los valores obtenidos del servicio 123.
   *
   * @author FSW IDS :::JMFR:::
   * @since 09/2015.
   * @param d de tipo String valor a formatear.
   * @param dec de tipo int numero de decimales.
   * @param porcentaje de tipo boolean si es de tipo porcentaje.
   * @return el string formateado.
   */
  public String formatearDecimal(String d, int dec, boolean porcentaje) {
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator('.');
    dfs.setGroupingSeparator(',');
    DecimalFormat df = new DecimalFormat("###,##0.00", dfs);
    if (d.length() == dec) {
      d = "0" + d;
      d = d.substring(0, d.length() - dec) + "." + d.substring(d.length() - dec);
    } else if (d.length() < dec) {
      int ceros = 0;
      ceros = dec - d.length() + 1;
      for (int i = 0; i < ceros; i++) {
        d = "0" + d;
      }
      d = d.substring(0, d.length() - dec) + "." + d.substring(d.length() - dec);
    } else {
      d = d.substring(0, d.length() - dec) + "." + d.substring(d.length() - dec);
    }
    if (porcentaje) {
      d = String.valueOf(Double.parseDouble(d));
    } else {
      d = String.valueOf(df.format(Double.parseDouble(d)));
    }

    return d;
  }
コード例 #3
0
  public void testToString() throws Exception {

    DecimalFormatSymbols symbols = new DecimalFormatSymbols();

    DvQuantity q = new DvQuantity("kg", 78, 2, ms);
    String expected = "78" + symbols.getDecimalSeparator() + "00 kg";
    assertEquals(expected, q.toString());

    q = new DvQuantity("kg", 78, ms);
    expected = "78 kg";
    assertEquals(expected, q.toString());

    q = new DvQuantity(78);
    expected = "78";
    assertEquals(expected, q.toString());

    q = new DvQuantity(78.9);
    expected = "79";
    assertEquals(expected, q.toString());

    q = new DvQuantity(78.5);
    expected = "78";
    assertEquals(expected, q.toString());

    q = new DvQuantity(78.5, 3, ms);
    expected = "78" + symbols.getDecimalSeparator() + "500";
    assertEquals(expected, q.toString());
  }
コード例 #4
0
ファイル: UEditView.java プロジェクト: kstep/ucalc
  public void toggleSign() {
    DecimalFormatSymbols symbols = ((DecimalFormat) formatter).getDecimalFormatSymbols();
    char minus = symbols.getMinusSign();
    String exp = symbols.getExponentSeparator();
    String text = getText().toString();

    int expPos = text.lastIndexOf(exp);
    if (expPos == -1) {
      if (text.charAt(0) == minus) {
        text = text.substring(1);
      } else {
        text = minus + text;
      }

    } else { // Exponent entered
      try {
        if (text.charAt(expPos + exp.length()) == minus) {
          text = text.substring(0, expPos) + exp + text.substring(expPos + exp.length() + 1);
        } else {
          text = text.substring(0, expPos) + exp + minus + text.substring(expPos + exp.length());
        }
      } catch (StringIndexOutOfBoundsException e) {
        text = text + minus;
      }
    }

    setText(text);
  }
コード例 #5
0
ファイル: MeioMaskField.java プロジェクト: shiraz79/core
  @Override
  public String getInput() {
    String input = super.getInput();

    if (input.trim().length() == 0 || isUnMaskableTypes(getType(), this.maskType)) {
      // Do nothing
      return input;
    } else if (isNumberFormat(getType())) { // Remove special characters
      DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols(getLocale());
      StringBuilder builder = new StringBuilder();
      for (int i = 0; i < input.length(); i++) {
        if (input.charAt(i) != formatSymbols.getGroupingSeparator()) {
          builder.append(input.charAt(i));
        }
      }
      return builder.toString();
    } else { // Unmask values
      try {
        LOGGER.debug("Value to Converter {}", input);
        return (String) maskFormatter.stringToValue(input);
      } catch (ParseException ex) {
        throw newConversionException(input, ex);
      }
    }
  }
コード例 #6
0
  /** @return Decimal format from EDI configuration */
  private DecimalFormat getDecimalFormatForConfiguration() {
    final DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance();

    final ModelCamelContext context = getContext();
    decimalFormat.setMaximumFractionDigits(
        Integer.valueOf(
            Util.resolvePropertyPlaceholders(context, "edi.decimalformat.maximumFractionDigits")));

    final boolean isGroupingUsed =
        Boolean.valueOf(
            Util.resolvePropertyPlaceholders(context, "edi.decimalformat.isGroupingUsed"));
    decimalFormat.setGroupingUsed(isGroupingUsed);

    final DecimalFormatSymbols decimalFormatSymbols = decimalFormat.getDecimalFormatSymbols();

    if (isGroupingUsed) {
      final char groupingSeparator =
          Util.resolvePropertyPlaceholders(context, "edi.decimalformat.symbol.groupingSeparator")
              .charAt(0);
      decimalFormatSymbols.setGroupingSeparator(groupingSeparator);
    }

    final char decimalSeparator =
        Util.resolvePropertyPlaceholders(context, "edi.decimalformat.symbol.decimalSeparator")
            .charAt(0);
    decimalFormatSymbols.setDecimalSeparator(decimalSeparator);

    decimalFormat.setDecimalFormatSymbols(
        decimalFormatSymbols); // though it seems redundant, it won't be set otherwise for some
                               // reason...

    return decimalFormat;
  }
コード例 #7
0
ファイル: Benchmark.java プロジェクト: huxi/lilith
  private void logBenchmark(String name, String action, long size, int amount, long expiredNanos) {
    double fraction = (double) expiredNanos / 1000000000;
    double eventsFraction = ((double) amount) / fraction;
    if (logger.isDebugEnabled()) logger.debug("{}: expired={}s", name, fraction);
    if (logger.isDebugEnabled()) logger.debug("{}: events/s={}", name, eventsFraction);
    if (logger.isDebugEnabled()) logger.debug("{}: size={} bytes", name, size);
    long eventAverage = size / amount;

    String formattedAverage =
        HumanReadable.getHumanReadableSize(eventAverage, true, false) + "bytes";
    String formattedLength = HumanReadable.getHumanReadableSize(size, true, false) + "bytes";
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setGroupingSeparator(',');
    symbols.setDecimalSeparator('.');
    DecimalFormat format = new DecimalFormat("#,##0.0#", symbols);
    String formattedEvents = format.format(eventsFraction);
    String formattedFraction = format.format(fraction);
    if (logger.isDebugEnabled()) logger.debug("average={}/event", name, formattedAverage);

    if (logger.isInfoEnabled()) {
      logger.info(
          "|| {} || {} || {} || {} || {} || {} ({}) || {} ||",
          new Object[] {
            name,
            action,
            amount,
            formattedFraction,
            formattedEvents,
            formattedLength,
            size,
            formattedAverage
          });
    }
  }
コード例 #8
0
  /**
   * Write the cluster and the segments to a CTL \e *FILE.
   *
   * @param dos the DataOutPutstream to write to
   * @throws IOException Signals that an I/O exception has occurred.
   */
  public void writeAsCTL(OutputStreamWriter dos) throws IOException {
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator('.');
    DecimalFormat df = new DecimalFormat();
    df.setDecimalFormatSymbols(dfs);
    df.setMaximumFractionDigits(2);
    df.setMinimumFractionDigits(2);
    df.setGroupingUsed(false);

    for (Segment seg : segmentSet) {
      float start = seg.getStartInSecond();
      float end = seg.getEndInSecond();
      String band = Segment.bandwidthNistStrings[0];
      if (seg.getBandwidth() == Segment.bandwidthStrings[1]) {
        band = Segment.bandwidthNistStrings[1];
      } else if (seg.getBandwidth() == Segment.bandwidthStrings[2]) {
        band = Segment.bandwidthNistStrings[2];
      }

      String line =
          seg.getShowName() + " " + seg.getStart() + " " + (seg.getStart() + seg.getLength());
      line += " " + seg.getShowName() + "-" + df.format(start) + "-" + df.format(end) + "-" + band;
      line += "-" + this.gender + "-" + name + "\n";
      dos.write(line);
    }
  }
  /** @tests java.text.DecimalFormatSymbols#setInternationalCurrencySymbol(java.lang.String) */
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "setInternationalCurrencySymbol",
      args = {java.lang.String.class})
  @KnownFailure("getCurrency() doesn't return null for bogus currency code.")
  public void test_setInternationalCurrencySymbolLjava_lang_String() {
    Locale locale = Locale.CANADA;
    DecimalFormatSymbols dfs =
        ((DecimalFormat) NumberFormat.getCurrencyInstance(locale)).getDecimalFormatSymbols();
    Currency currency = Currency.getInstance("JPY");
    dfs.setInternationalCurrencySymbol(currency.getCurrencyCode());

    assertTrue("Test1: Returned incorrect currency", currency == dfs.getCurrency());
    assertEquals(
        "Test1: Returned incorrect currency symbol",
        currency.getSymbol(locale),
        dfs.getCurrencySymbol());
    assertTrue(
        "Test1: Returned incorrect international currency symbol",
        currency.getCurrencyCode().equals(dfs.getInternationalCurrencySymbol()));

    String symbol = dfs.getCurrencySymbol();
    dfs.setInternationalCurrencySymbol("bogus");
    assertNull("Test2: Returned incorrect currency", dfs.getCurrency());
    assertTrue("Test2: Returned incorrect currency symbol", dfs.getCurrencySymbol().equals(symbol));
    assertEquals(
        "Test2: Returned incorrect international currency symbol",
        "bogus",
        dfs.getInternationalCurrencySymbol());
  }
コード例 #10
0
 static {
   DecimalFormatSymbols sym = fdec3.getDecimalFormatSymbols();
   sym.setDecimalSeparator('.');
   fdec3.setDecimalFormatSymbols(sym);
   fdec3.setMaximumFractionDigits(3);
   fdec3.setMinimumIntegerDigits(1);
 }
コード例 #11
0
ファイル: Language.java プロジェクト: omidp/iranAdempiere
 /**
  * Returns true if Decimal Point (not comma)
  *
  * @return use of decimal point
  */
 public boolean isDecimalPoint() {
   if (m_decimalPoint == null) {
     DecimalFormatSymbols dfs = new DecimalFormatSymbols(m_locale);
     m_decimalPoint = new Boolean(dfs.getDecimalSeparator() == '.');
   }
   return m_decimalPoint.booleanValue();
 } //  isDecimalPoint
コード例 #12
0
 public static String bigDecimal2String(BigDecimal value) {
   DecimalFormat format = new DecimalFormat("0.##");
   DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
   symbols.setDecimalSeparator('.');
   format.setDecimalFormatSymbols(symbols);
   format.setDecimalSeparatorAlwaysShown(false);
   return format.format(value);
 }
コード例 #13
0
 String defaultValue() {
   DecimalFormatSymbols symbols = ((DecimalFormat) numberFormat).getDecimalFormatSymbols();
   if (symbols.getDecimalSeparator() == '.') {
     return "0.0";
   } else {
     return "0,0";
   }
 }
コード例 #14
0
ファイル: VideoCutter.java プロジェクト: thorsten-k/otrcast
 public static synchronized String getSecond(double d) {
   if (df == null) {
     DecimalFormatSymbols dfs = new DecimalFormatSymbols();
     dfs.setDecimalSeparator('.');
     df = new DecimalFormat("0.00", dfs);
   }
   return df.format(d);
 }
 /** @tests java.text.DecimalFormatSymbols#setZeroDigit(char) */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "setZeroDigit",
     args = {char.class})
 public void test_setZeroDigitC() {
   dfs.setZeroDigit('*');
   assertEquals("Set incorrect ZeroDigit symbol", '*', dfs.getZeroDigit());
 }
 /** @tests java.text.DecimalFormatSymbols#setPerMill(char) */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "setPerMill",
     args = {char.class})
 public void test_setPerMillC() {
   dfs.setPerMill('#');
   assertEquals("Returned incorrect PerMill symbol", '#', dfs.getPerMill());
 }
 /** @tests java.text.DecimalFormatSymbols#setPatternSeparator(char) */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "setPatternSeparator",
     args = {char.class})
 public void test_setPatternSeparatorC() {
   dfs.setPatternSeparator('X');
   assertEquals("Returned incorrect PatternSeparator symbol", 'X', dfs.getPatternSeparator());
 }
 /** @tests java.text.DecimalFormatSymbols#setNaN(java.lang.String) */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "setNaN",
     args = {java.lang.String.class})
 public void test_setNaNLjava_lang_String() {
   dfs.setNaN("NAN!!");
   assertEquals("Returned incorrect nan symbol", "NAN!!", dfs.getNaN());
 }
 /** @tests java.text.DecimalFormatSymbols#setMinusSign(char) */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "setMinusSign",
     args = {char.class})
 public void test_setMinusSignC() {
   dfs.setMinusSign('&');
   assertEquals("Returned incorrect MinusSign symbol", '&', dfs.getMinusSign());
 }
コード例 #20
0
 @Override
 protected DecimalFormat initialValue() {
   symbols.setGroupingSeparator(',');
   symbols.setDecimalSeparator('.');
   String pattern = "#,##0.0#";
   DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols);
   decimalFormat.setParseBigDecimal(true);
   return decimalFormat;
 }
 /** @tests java.text.DecimalFormatSymbols#setInfinity(java.lang.String) */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "setInfinity",
     args = {java.lang.String.class})
 public void test_setInfinityLjava_lang_String() {
   dfs.setInfinity("&");
   assertTrue("Returned incorrect Infinity symbol", dfs.getInfinity() == "&");
 }
 /** @tests java.text.DecimalFormatSymbols#getZeroDigit() */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "getZeroDigit",
     args = {})
 public void test_getZeroDigit() {
   dfs.setZeroDigit('*');
   assertEquals("Returned incorrect ZeroDigit symbol", '*', dfs.getZeroDigit());
 }
 /** @tests java.text.DecimalFormatSymbols#getNaN() */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "getNaN",
     args = {})
 public void test_getNaN() {
   dfs.setNaN("NAN!!");
   assertEquals("Returned incorrect nan symbol", "NAN!!", dfs.getNaN());
 }
 /** @tests java.text.DecimalFormatSymbols#getInfinity() */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "getInfinity",
     args = {})
 public void test_getInfinity() {
   dfs.setInfinity("&");
   assertTrue("Returned incorrect Infinity symbol", dfs.getInfinity() == "&");
 }
 /** @tests java.text.DecimalFormatSymbols#getGroupingSeparator() */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "getGroupingSeparator",
     args = {})
 public void test_getGroupingSeparator() {
   dfs.setGroupingSeparator('*');
   assertEquals("Returned incorrect GroupingSeparator symbol", '*', dfs.getGroupingSeparator());
 }
コード例 #26
0
ファイル: DataUtil.java プロジェクト: guihuoliuying/CoolSQL
 public static final DecimalFormat createTimingFormatter() {
   DecimalFormatSymbols symb = new DecimalFormatSymbols();
   String sep =
       Setting.getInstance().getProperty(PropertyConstant.PROPERTY_COMMON_DATAFORMATER_SEP, ".");
   symb.setDecimalSeparator(sep.charAt(0));
   DecimalFormat numberFormatter = new DecimalFormat("0.#s", symb);
   numberFormatter.setMaximumFractionDigits(2);
   return numberFormatter;
 }
コード例 #27
0
  public static DecimalFormat getDecimalFormat() {

    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.ITALIAN);
    otherSymbols.setDecimalSeparator('.');
    otherSymbols.setGroupingSeparator('\0');
    DecimalFormat df = new DecimalFormat("#.00", otherSymbols);
    df.setGroupingUsed(false);
    return df;
  }
コード例 #28
0
 private static DecimalFormat getFormatterWithSymbol(Locale displayLocale, Currency currency) {
   DecimalFormat formatter = (DecimalFormat) NumberFormat.getCurrencyInstance(displayLocale);
   formatter.setCurrency(currency);
   DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
   String currencySymbol = getCountryCodeFreeCurrencySymbol(currency);
   symbols.setCurrencySymbol(currencySymbol);
   formatter.setDecimalFormatSymbols(symbols);
   return formatter;
 }
コード例 #29
0
  static {
    final DecimalFormatSymbols dotDecimalSeparator = new DecimalFormatSymbols();
    dotDecimalSeparator.setDecimalSeparator('.');
    ASS_DECIMAL_FORMAT.setDecimalFormatSymbols(dotDecimalSeparator);

    final DecimalFormatSymbols commaDecimalSeparator = new DecimalFormatSymbols();
    commaDecimalSeparator.setDecimalSeparator(',');
    SRT_DECIMAL_FORMAT.setDecimalFormatSymbols(commaDecimalSeparator);
  }
コード例 #30
0
ファイル: getCurrency.java プロジェクト: niloc132/mauve-gwt
 public void test(TestHarness harness) {
   try {
     DecimalFormatSymbols dfs = new DecimalFormatSymbols(new Locale("foobar"));
     harness.check(dfs.getCurrency().toString().equals("XXX"));
   } catch (Exception x) {
     harness.debug(x);
     harness.check(false);
   }
 }