package com.example.simpleCalculator.server.model;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Conversion {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent
	private Date timestamp;
	@Persistent
	private String decimal;
	@Persistent
	private String binary;

	public Conversion(String decimal) {
		this.timestamp = new Date();
		this.decimal = decimal;
		this.binary = convertToBinary(decimal);
	}

	public Long getId() {
		return this.id;
	}

	public String getDecimal() {
		return this.decimal;
	}

	public String getBinary() {
		return this.binary;
	}

	public Date getTimestamp() {
		return this.timestamp;
	}
	 
	@Override
	public String toString() {
		SimpleDateFormat format = new SimpleDateFormat("YYYY/MM/dd HH:mm:ss.SSS");
		String dateString = format.format(this.timestamp);
		
		return new String("\"" + dateString + "\",\"" + this.getDecimal() + "\",\"" + this.getBinary() + "\"");
	}
	
	private String convertToBinary(String decimal) {
		String ret = "";
		try {
			int dec = Integer.valueOf(decimal);
			ret = String.format("%8s", Integer.toBinaryString(dec)).replace(' ', '0');
		}
		catch(NumberFormatException e) {
		}
		
		return ret;
	}
}

@@ -1351,23 +1351,22 @@
 t dec = 
-Integer
+Double
 .valueOf
@@ -1374,16 +1374,27 @@
 decimal)
+.intValue()
 ;%0A%09%09%09ret

Allow convert to decimal the integer part of real values.