Velocity Number Tool Currency Locale : Number Tool « Velocity « Java






Velocity Number Tool Currency Locale


import java.io.StringWriter;
import java.io.Writer;
import java.util.Locale;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.tools.generic.NumberTool;

public class NumberToolExample {

  public static void main(String[] args) throws Exception {
    Velocity.init();

    Template t = Velocity.getTemplate("./src/numberTool.vm");

    VelocityContext ctx = new VelocityContext();
    ctx.put("number", new NumberTool());
    ctx.put("aNumber", new Double(0.95));
    ctx.put("aLocale", Locale.UK);

    Writer writer = new StringWriter();
    t.merge(ctx, writer);

    System.out.println(writer);
  }
}
-------------------------------------------------------------------------------------
Currency (with Locale): $number.format("currency", $aNumber, $aLocale)
           
       








velocity-NumberTool-CurrencyLocale.zip( 875 k)

Related examples in the same category

1.Velocity NumberTool Currency Formatting
2.Velocity Number Tool Integer Format
3.Velocity Number Tool Percentage Format