⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 floatatom.java

📁 类似于Windows上的Excel
💻 JAVA
字号:
/*
 * MC2 -- j2me spreadsheet
 *
 * Copyright (c) 2004-2006 Michael Zemljanukha (mixaz@mail.ru)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package com.wapindustrial.calc;

import ral.Real;

/**
 *
 * @author  mixa
 * @version
 */
public class FloatAtom extends LispObject {
    public static final FloatAtom ZERO = new FloatAtom( Real.ZERO );
    Real value;

    static Real.NumberFormat nformat;
    
    static {
      nformat = new Real.NumberFormat();
      nformat.removePoint=false;
    }

//    public FloatAtom() {
//      value = Real.ZERO;
//    }
    public FloatAtom( Real value ) {
        this.value = value;
    }
    public FloatAtom( long value ) {
        this.value = new Real(value);
    }
    public FloatAtom( int value ) {
        this.value = new Real(value);
    }
    public static FloatAtom convertFromLong( long value ) {
        return new FloatAtom( new Real(value) );
    }
    public FloatAtom( String ss ) {
        value = new Real( ss );
    }
    
    public long toLong() {
        return value.toLong();
    }
    
    public void toBuffer( StringBuffer sb ) {
        sb.append( value.toString( nformat ) );
    }

    public void toJavaBuffer( StringBuffer sb, int ident, FunctorList parent ) {
        addIdent( sb, ident );
        sb.append( "new FloatAtom(\"" );
        toBuffer( sb );
        sb.append( "\") " );
    }

    public int typeNumber() {
        return TYPE_FLOAT;
    }
    
    public LispObject convertToType( int type ) throws EvaluateException {
        LispObject rez = this;
        switch( type ) {
            case TYPE_SHORT:
                rez = new ShortAtom( value.toInteger() );
                break;
            case TYPE_LONG:
                rez = new LongAtom( value.toLong() );
                break;
            case TYPE_FLOAT:
                break;
            case TYPE_DATE:
		Real tmp = new Real( value );
		tmp.toDHMS();
                rez = new DateAtom( tmp );
                break;
            default:    // to STRING
                return super.convertToType( type );
        }
        return rez;
    }
    
    static String TrimZeroes( String ss ) {
        int nn = ss.length()-1;
        char cc;
        while( (cc=ss.charAt(nn)) == '0' )
            nn--;
        if( cc == '.' ) nn++;
        return ss.substring( 0, nn+1 );
    }
    void add0( FloatAtom ff ) { value.add(ff.value); }
    void sub0( FloatAtom ff ) { value.sub(ff.value); }
    void mul0( FloatAtom ff ) { value.mul(ff.value); }
    void div0( FloatAtom ff ) { value.div(ff.value); }
    
    boolean gt( FloatAtom ff ) { return value.greaterThan(ff.value); }
    boolean ge( FloatAtom ff ) { return value.greaterEqual(ff.value); }
    boolean lt( FloatAtom ff ) { return value.lessThan(ff.value); }
    boolean le( FloatAtom ff ) { return value.lessEqual(ff.value); }
    boolean eq( FloatAtom ff ) { return value.equalTo(ff.value); }
    boolean ne( FloatAtom ff ) { return value.notEqualTo(ff.value); }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -