Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

In this page you can find the example usage for java.text NumberFormat format.

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

Usage

From source file:handlers.voicedcommands.WhoAmI.java

/**
 * Method useVoicedCommand.//from  w ww .jav a  2 s . c  om
 * @param command String
 * @param player Player
 * @param args String
 * @return boolean
 * @see lineage2.gameserver.handlers.IVoicedCommandHandler#useVoicedCommand(String, Player, String)
 */
@Override
public boolean useVoicedCommand(String command, Player player, String args) {
    Creature target = null;
    double hpRegen = Formulas.calcHpRegen(player);
    double cpRegen = Formulas.calcCpRegen(player);
    double mpRegen = Formulas.calcMpRegen(player);
    double hpDrain = player.calcStat(Stats.ABSORB_DAMAGE_PERCENT, 0., target, null);
    double mpDrain = player.calcStat(Stats.ABSORB_DAMAGEMP_PERCENT, 0., target, null);
    double hpGain = player.calcStat(Stats.HEAL_EFFECTIVNESS, 100., target, null);
    double mpGain = player.calcStat(Stats.MANAHEAL_EFFECTIVNESS, 100., target, null);
    double critPerc = 2 * player.calcStat(Stats.CRITICAL_DAMAGE, target, null);
    double critStatic = player.calcStat(Stats.CRITICAL_DAMAGE_STATIC, target, null);
    double mCritDmg = player.calcStat(Stats.MCRITICAL_DAMAGE, target, null);
    double blowRate = player.calcStat(Stats.FATALBLOW_RATE, target, null);
    ItemInstance shld = player.getSecondaryWeaponInstance();
    boolean shield = (shld != null) && (shld.getItemType() == WeaponType.NONE);
    double shieldDef = shield
            ? player.calcStat(Stats.SHIELD_DEFENCE, player.getTemplate().getBaseShldDef(), target, null)
            : 0.;
    double shieldRate = shield ? player.calcStat(Stats.SHIELD_RATE, target, null) : 0.;
    double xpRate = player.getRateExp();
    double spRate = player.getRateSp();
    double dropRate = player.getRateItems();
    double adenaRate = player.getRateAdena();
    double spoilRate = player.getRateSpoil();
    double fireResist = player.calcStat(Element.FIRE.getDefence(), 0., target, null);
    double windResist = player.calcStat(Element.WIND.getDefence(), 0., target, null);
    double waterResist = player.calcStat(Element.WATER.getDefence(), 0., target, null);
    double earthResist = player.calcStat(Element.EARTH.getDefence(), 0., target, null);
    double holyResist = player.calcStat(Element.HOLY.getDefence(), 0., target, null);
    double unholyResist = player.calcStat(Element.UNHOLY.getDefence(), 0., target, null);
    double bleedPower = player.calcStat(Stats.BLEED_POWER, target, null);
    double bleedResist = player.calcStat(Stats.BLEED_RESIST, target, null);
    double poisonPower = player.calcStat(Stats.POISON_POWER, target, null);
    double poisonResist = player.calcStat(Stats.POISON_RESIST, target, null);
    double stunPower = player.calcStat(Stats.STUN_POWER, target, null);
    double stunResist = player.calcStat(Stats.STUN_RESIST, target, null);
    double rootPower = player.calcStat(Stats.ROOT_POWER, target, null);
    double rootResist = player.calcStat(Stats.ROOT_RESIST, target, null);
    double sleepPower = player.calcStat(Stats.SLEEP_POWER, target, null);
    double sleepResist = player.calcStat(Stats.SLEEP_RESIST, target, null);
    double paralyzePower = player.calcStat(Stats.PARALYZE_POWER, target, null);
    double paralyzeResist = player.calcStat(Stats.PARALYZE_RESIST, target, null);
    double mentalPower = player.calcStat(Stats.MENTAL_POWER, target, null);
    double mentalResist = player.calcStat(Stats.MENTAL_RESIST, target, null);
    double debuffPower = player.calcStat(Stats.DEBUFF_POWER, target, null);
    double debuffResist = player.calcStat(Stats.DEBUFF_RESIST, target, null);
    double cancelPower = player.calcStat(Stats.CANCEL_POWER, target, null);
    double cancelResist = player.calcStat(Stats.CANCEL_RESIST, target, null);
    double swordResist = 100. - player.calcStat(Stats.SWORD_WPN_VULNERABILITY, target, null);
    double dualResist = 100. - player.calcStat(Stats.DUAL_WPN_VULNERABILITY, target, null);
    double bluntResist = 100. - player.calcStat(Stats.BLUNT_WPN_VULNERABILITY, target, null);
    double daggerResist = 100. - player.calcStat(Stats.DAGGER_WPN_VULNERABILITY, target, null);
    double bowResist = 100. - player.calcStat(Stats.BOW_WPN_VULNERABILITY, target, null);
    double crossbowResist = 100. - player.calcStat(Stats.CROSSBOW_WPN_VULNERABILITY, target, null);
    double poleResist = 100. - player.calcStat(Stats.POLE_WPN_VULNERABILITY, target, null);
    double fistResist = 100. - player.calcStat(Stats.FIST_WPN_VULNERABILITY, target, null);
    double critChanceResist = 100. - player.calcStat(Stats.CRIT_CHANCE_RECEPTIVE, target, null);
    double critDamResistStatic = player.calcStat(Stats.CRIT_DAMAGE_RECEPTIVE, target, null);
    double critDamResist = 100.
            - (100 * (player.calcStat(Stats.CRIT_DAMAGE_RECEPTIVE, 1., target, null) - critDamResistStatic));
    String dialog = HtmCache.getInstance().getNotNull("command/whoami.htm", player);
    NumberFormat df = NumberFormat.getInstance(Locale.ENGLISH);
    df.setMaximumFractionDigits(1);
    df.setMinimumFractionDigits(1);
    StrBuilder sb = new StrBuilder(dialog);
    sb.replaceFirst("%hpRegen%", df.format(hpRegen));
    sb.replaceFirst("%cpRegen%", df.format(cpRegen));
    sb.replaceFirst("%mpRegen%", df.format(mpRegen));
    sb.replaceFirst("%hpDrain%", df.format(hpDrain));
    sb.replaceFirst("%mpDrain%", df.format(mpDrain));
    sb.replaceFirst("%hpGain%", df.format(hpGain));
    sb.replaceFirst("%mpGain%", df.format(mpGain));
    sb.replaceFirst("%critPerc%", df.format(critPerc));
    sb.replaceFirst("%critStatic%", df.format(critStatic));
    sb.replaceFirst("%mCritDmg%", df.format(mCritDmg));
    sb.replaceFirst("%blowRate%", df.format(blowRate));
    sb.replaceFirst("%shieldDef%", df.format(shieldDef));
    sb.replaceFirst("%shieldRate%", df.format(shieldRate));
    sb.replaceFirst("%xpRate%", df.format(xpRate));
    sb.replaceFirst("%spRate%", df.format(spRate));
    sb.replaceFirst("%dropRate%", df.format(dropRate));
    sb.replaceFirst("%adenaRate%", df.format(adenaRate));
    sb.replaceFirst("%spoilRate%", df.format(spoilRate));
    sb.replaceFirst("%fireResist%", df.format(fireResist));
    sb.replaceFirst("%windResist%", df.format(windResist));
    sb.replaceFirst("%waterResist%", df.format(waterResist));
    sb.replaceFirst("%earthResist%", df.format(earthResist));
    sb.replaceFirst("%holyResist%", df.format(holyResist));
    sb.replaceFirst("%darkResist%", df.format(unholyResist));
    sb.replaceFirst("%bleedPower%", df.format(bleedPower));
    sb.replaceFirst("%bleedResist%", df.format(bleedResist));
    sb.replaceFirst("%poisonPower%", df.format(poisonPower));
    sb.replaceFirst("%poisonResist%", df.format(poisonResist));
    sb.replaceFirst("%stunPower%", df.format(stunPower));
    sb.replaceFirst("%stunResist%", df.format(stunResist));
    sb.replaceFirst("%rootPower%", df.format(rootPower));
    sb.replaceFirst("%rootResist%", df.format(rootResist));
    sb.replaceFirst("%sleepPower%", df.format(sleepPower));
    sb.replaceFirst("%sleepResist%", df.format(sleepResist));
    sb.replaceFirst("%paralyzePower%", df.format(paralyzePower));
    sb.replaceFirst("%paralyzeResist%", df.format(paralyzeResist));
    sb.replaceFirst("%mentalPower%", df.format(mentalPower));
    sb.replaceFirst("%mentalResist%", df.format(mentalResist));
    sb.replaceFirst("%debuffPower%", df.format(debuffPower));
    sb.replaceFirst("%debuffResist%", df.format(debuffResist));
    sb.replaceFirst("%cancelPower%", df.format(cancelPower));
    sb.replaceFirst("%cancelResist%", df.format(cancelResist));
    sb.replaceFirst("%swordResist%", df.format(swordResist));
    sb.replaceFirst("%dualResist%", df.format(dualResist));
    sb.replaceFirst("%bluntResist%", df.format(bluntResist));
    sb.replaceFirst("%daggerResist%", df.format(daggerResist));
    sb.replaceFirst("%bowResist%", df.format(bowResist));
    sb.replaceFirst("%crossbowResist%", df.format(crossbowResist));
    sb.replaceFirst("%fistResist%", df.format(fistResist));
    sb.replaceFirst("%poleResist%", df.format(poleResist));
    sb.replaceFirst("%critChanceResist%", df.format(critChanceResist));
    sb.replaceFirst("%critDamResist%", df.format(critDamResist));
    NpcHtmlMessage msg = new NpcHtmlMessage(0);
    msg.setHtml(Strings.bbParse(sb.toString()));
    player.sendPacket(msg);
    return true;
}

From source file:clus.statistic.RegressionStatBase.java

public void printDistribution(PrintWriter wrt) throws IOException {
    NumberFormat fr = ClusFormat.SIX_AFTER_DOT;
    for (int i = 0; i < m_Attrs.length; i++) {
        wrt.print(StringUtils.printStr(m_Attrs[i].getName(), 35));
        wrt.print(" [");
        wrt.print(fr.format(getMean(i)));
        wrt.print(",");
        wrt.print(fr.format(getVariance(i)));
        wrt.println("]");
    }//from ww w  .  java 2  s .c o  m
}

From source file:com.anrisoftware.globalpom.format.degree.DegreeSexagesimalFormat.java

private void formatFormat(StringBuffer buff, double value) {
    NumberFormat format = DecimalFormat.getNumberInstance();
    double degree = (long) value;
    double dmin = abs((value - degree) / MIN);
    double min = roundToDecimal((long) dmin, decimal);
    double sec = roundToDecimal((dmin - min) / MIN, decimal);
    buff.append(format.format(degree));
    buff.append(DEGREE_SUB);// w  w w . jav a 2s . c  o  m
    if (min > epsilon) {
        buff.append(format.format(min));
        buff.append(MIN_SUB);
    }
    if (sec > epsilon) {
        buff.append(format.format(sec));
        buff.append(SEC_SUB);
    }
}

From source file:Money.java

public String displayAsDollars() {
    NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);

    if (delegate.signum() < 0) {
        this.delegate = delegate.negate();
        //String dis = "-$" + this.toString();
        this.delegate = this.delegate.negate();
        //return dis;
        return nf.format(this.delegate);
    } else {/*  www  . j a v a2  s  .c om*/
        return nf.format(this.delegate);
        //return "$" + toString();
    }
}

From source file:com.prowidesoftware.swift.model.field.Field110.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from w ww . java2s .  c o  m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 110");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field122.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//  ww w. j a v  a 2  s.  c  om
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 122");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field349.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from w  ww  . j  av  a2  s  .  c o m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 349");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field451.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//from   www. jav  a  2s .co  m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 451");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field533.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//from w  ww.j  av a2 s.  com
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 533");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:org.davidmendoza.esu.web.admin.ArticuloController.java

private void inicializaPublicacion(Model model, Publicacion publicacion) {
    List<Integer> anios = new ArrayList<>();
    for (int i = (publicacion.getAnio() + 1); i >= 2011; i--) {
        anios.add(i);/* w w w .  j a v  a2  s. c  o  m*/
    }
    model.addAttribute("anios", anios);

    List<String> trimestres = new ArrayList<>();
    trimestres.add("t1");
    trimestres.add("t2");
    trimestres.add("t3");
    trimestres.add("t4");
    model.addAttribute("trimestres", trimestres);

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumIntegerDigits(2);
    List<String> lecciones = new ArrayList<>();
    for (int i = 1; i < 15; i++) {
        lecciones.add("l" + nf.format(i));
    }
    model.addAttribute("lecciones", lecciones);

    List<String> temas = new ArrayList<>();
    temas.add("tema1");
    temas.add("tema2");
    temas.add("tema3");
    temas.add("tema4");
    temas.add("tema5");
    model.addAttribute("temas", temas);

    List<String> tipos = new ArrayList<>();
    tipos.add("comunica");
    tipos.add("dialoga");
    tipos.add("leccion");
    tipos.add("versiculo");
    tipos.add("video");
    tipos.add("imagen");
    tipos.add("jovenes");
    tipos.add("podcast");
    model.addAttribute("tipos", tipos);

    List<String> dias = new ArrayList<>();
    dias.add("domingo");
    dias.add("lunes");
    dias.add("martes");
    dias.add("miercoles");
    dias.add("jueves");
    dias.add("viernes");
    dias.add("sabado");
    model.addAttribute("dias", dias);

    List<String> estados = new ArrayList<>();
    estados.add("PUBLICADO");
    estados.add("PENDIENTE");
    estados.add("RECHAZADO");
    model.addAttribute("estados", estados);
}