Package com.nykredit.kundeservice.tcm

Source Code of com.nykredit.kundeservice.tcm.Formatter

package com.nykredit.kundeservice.tcm;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.joda.time.LocalTime;

/**
*
* Formats used when presenting data in tables
*
* @author thra
*
*/
public class Formatter {
   
  public static String toNumberString(Double number){
    if(number == null)
      return "-";
   
    NumberFormat formatter = new DecimalFormat("#,###,##0.#");
   
    return formatter.format(number);
  }
  public static String toNumberString(Integer number){
    if(number == null)
      return "-";
   
    NumberFormat formatter = new  DecimalFormat("##,###,##0.#");
   
    return formatter.format(number);
  }
  public static String toPercentString(Double number){
    if(number == null)
      return null;
   
    NumberFormat formatter = new DecimalFormat("##0");
   
    return formatter.format(Math.round(number * 100)) + "%";
  }
  public static String toPercentString(Integer number){
    if(number == null)
      return null;
   
    NumberFormat formatter = new DecimalFormat("##0");
   
    return formatter.format(Math.round(number * 100)) + "%";
  }
 
  public static String toTimeString(Integer seconds){
    return new LocalTime(0,
               seconds / 60,
               seconds % 60).toString("mm:ss");
  }

  public static String toBooleanString(Boolean value){
    if(value == null || value == false)
      return "Ikke opfyldt";
    else
      return "Opfyldt";
  }
}
TOP

Related Classes of com.nykredit.kundeservice.tcm.Formatter

TOP
Copyright © 2018 www.massapi.com. 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.