package jxl.read.biff;

import common.Logger;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import jxl.CellType;
import jxl.NumberCell;
import jxl.biff.DoubleHelper;
import jxl.biff.FormattingRecords;

class NumberRecord extends CellValue implements NumberCell {
  private static Logger logger = Logger.getLogger(NumberRecord.class);
  
  private double value;
  
  private NumberFormat format;
  
  private static DecimalFormat defaultFormat = new DecimalFormat("#.###");
  
  public NumberRecord(Record t, FormattingRecords fr, SheetImpl si) {
    super(t, fr, si);
    byte[] data = getRecord().getData();
    this.value = DoubleHelper.getIEEEDouble(data, 6);
    this.format = fr.getNumberFormat(getXFIndex());
    if (this.format == null)
      this.format = defaultFormat; 
  }
  
  public double getValue() {
    return this.value;
  }
  
  public String getContents() {
    return this.format.format(this.value);
  }
  
  public CellType getType() {
    return CellType.NUMBER;
  }
  
  public NumberFormat getNumberFormat() {
    return this.format;
  }
}
