Java导出防止小数显示不全工具类

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

1、说明

     在做项目的过程中,发现导出功能中的数据显示不全,如“0.4”,会显示成“.4”;“-0.8”会显示成“-.8”

     现在,通过以下Java工具类保证导出的数据(特别是小数)显示全


2、Java工具类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
 * @Title:DecimalPoint.java
 * @Package:com.you.model
 * @Description:解决导出时小数前的“0”被去掉的问题
 * @Author: 游海东
 * @date: 2014年7月8日 下午9:13:52
 * @Version V1.2.3
 */ 
package com.you.model; 
   
/**
 * @类名:DecimalPoint
 * @描述:
 * @Author:
 * @date: 2014年7月8日 下午9:13:52
 */ 
public class DecimalPoint  
    /**
     
     * @Title : findPoint
     * @Type : DecimalPoint
     * @date : 2014年7月8日 下午9:16:20
     * @Description : 
     * @param number
     * @return
     */ 
    public static String findPoint(String number) 
    
        //当参数为空时,返回"" 
        if(null == number) 
        
            return ""
        
        //防止出现“.6” 
        if(number.startsWith(".")) 
        
            number = "0" + number; 
        
        //防止出现“-.6” 
        else if(number.startsWith("-.")) 
        
            number = "-0" + number.substring(1,number.length()); 
        
           
        return number; 
    
       
    /**
     * @Title : main
     * @Type : DecimalPoint
     * @date : 2014年7月8日 下午9:13:55
     * @Description : 
     * @param args
     */ 
    public static void main(String[] args)  
    
        //传“.8” 
        String numOne = ".8"
        //传“-.7” 
        String numTwo = "-.7"
        String resultOne = findPoint(numOne); 
        String resultTwo = findPoint(numTwo); 
        System.out.println("正小数:" + resultOne + "\n" + "负小数:" + resultTwo); 
    
   
}

3、实现结果
1
2
正小数:0.8 
负小数:-0.7
来自: