Android sqlite 数据类型

来源:互联网 发布:郑州淘宝客服招聘包住 编辑:程序博客网 时间:2024/06/01 10:38

场景:一直做金融行业项目,所以数据的精确性十分重要

执行代码查询数据(数据精确到小数点2位)和直接执行SqL所查询数据不一致,经排查发现

 value = cursor.getString(cursor.getColumnIndex(ss[i]));在作怪,此方法对Double数据进行了怎样处理,还需深究

解决方法如下

if(cursor.getType(cursor.getColumnIndex(ss[i])) == Cursor.FIELD_TYPE_FLOAT){value = cursor.getDouble(cursor.getColumnIndex(ss[i]))+"";} else {    value = cursor.getString(cursor.getColumnIndex(ss[i]));}


SQLite具有以下五种数据类型:

1.NULL:空值。
  2.INTEGER:带符号的整型,具体取决有存入数字的范围大小。
  3.REAL:浮点数字,存储为8-byte IEEE浮点数。
  4.TEXT:字符串文本。

5.BLOB:二进制对象。


 /** Value returned by {@link #getType(int)} if the specified column is null */
    static final int FIELD_TYPE_NULL = 0;


    /** Value returned by {@link #getType(int)} if the specified  column type is integer */
    static final int FIELD_TYPE_INTEGER = 1;


    /** Value returned by {@link #getType(int)} if the specified column type is float */
    static final int FIELD_TYPE_FLOAT = 2;


    /** Value returned by {@link #getType(int)} if the specified column type is string */
    static final int FIELD_TYPE_STRING = 3;


    /** Value returned by {@link #getType(int)} if the specified column type is blob */
    static final int FIELD_TYPE_BLOB = 4;


0 0
原创粉丝点击