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


    1、说明

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

         如今。通过下面Java工具类保证导出的数据(特别是小数)显示全


    2、Java工具类

    /**
     * @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 + "
    " + "负小数:" + resultTwo);
    	}
    
    }
    

    3、实现结果

    正小数:0.8
    负小数:-0.7


  • 相关阅读:
    2-Requests库的使用
    1-urllib库的使用
    (一)数据结构-基本数学知识
    maven配置阿里云仓库
    mac安装homebrew
    创建简单spring boot项目
    Java反射
    Python3 去除空格
    Spot 安装和使用
    安装LLVM
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/6814497.html
Copyright © 2020-2023  润新知