类型double float数据类型,计算机中表示实型变量的一种变量类型。此数据类型与单精度数据类型(float)相似,但精确度比float高,编译时所占的内存空间依不同的编译器而有所不同,通常情况,单精度浮点数占4字节(32位)内存空间,其数值范围为3.4E-38~3.4E+38,;双精度型占8 个字节(64位)内存空间,其数值范围为1.7E-308~1.7E+308。
具体实例代码如下:
package com.yoodb; import com.google.gson.Gson; public class DoubleMain { public static void main(String[] args) { double[] dou = { 9, 1.2, 5, 3.2, 1.1 }; orderNum(dou); } /** * double 和 int 数字排序 * @author www.yoodb.com * @param dou 数组 */ public static void orderNum(double[] dou) { for (int i = 0; i < dou.length - 1; i++) { for (int j = 0; j < dou.length - 1 - i; j++) { double temp = 0; if (dou[j] > dou[j + 1]) { temp = dou[j + 1]; dou[j + 1] = dou[j]; dou[j] = temp; } } } System.out.println("排序后:" + new Gson().toJson(dou)); /** * 这里是过滤掉整数的double类型 */ for (int i = 0; i < dou.length; i++) { int temp = (int) dou[i]; if (dou[i] % temp == 0) { System.out.println(temp); } else { System.out.println(dou[i]); } } } }
上述代码中使用了google的开源类库gson,如果不是很了解参考地址:http://blog.yoodb.com/yoodb/article/detail/1033