搜尋
首頁資料庫mysql教程如何使数据库中大的浮点数正常显示,不变成科学计数法显示

在公司实习时候发现个问题,就是大的浮点数从数据库取出后变成了科学计数法显示,而原有的验证控件并不能识别科学技术法,造成数据无法正常保存,临时找到了个解决办法。 当输入大数据的时候浮点类型在从数据库取出的时候会以科学计数法的形式显示。 比如输

              在公司实习时候发现个问题,就是大的浮点数从数据库取出后变成了科学计数法显示,而原有的验证控件并不能识别科学技术法,造成数据无法正常保存,临时找到了个解决办法。

  当输入大数据的时候浮点类型在从数据库取出的时候会以科学计数法的形式显示。

  比如输入:2222222222 回显时页面显示为:2.222222222E9 这样在修改时候无法正常保存。  

  解决办法:

1.方法一

  例如车辆单价:

  注意黑体字部分是车辆单价的显示方式,maxIntegerDigits为整数部分显示的最大长度,maxFractionDigits为小数部分显示的最大长度。

  这样可以将2.222222222E9转化成2,222,222,222 之后采用字符串匹配方式去掉” , ”,采用正则表达式处理,函数为

2.方法二

用正则表达式处理字符串,去掉格式化之后的浮点数类型

function formatNum(id){                          

       document.getElementById(id).value=document.getElementById(id).value.replace(/,/gi,'');

}

 这个函数可以将2,222,222,222中的” , ”去掉,使其正常显示。

其中id为输入框的id。

的onload属性中添加如下语句调用formatNum("cldj"); 

 

 
 3.方法三

代码如下 

 
          
             java.text.DecimalFormat df=new java.text.DecimalFormat("#0.00000");//指定转换的格式
       Object cash=request.getAttribute("cash");
       if("".equals(cash)||cash==null){cash="0";}
       String str=df.format(cash);//将double类型的值转换为String类型
      %>
     
          

4.方法四

import java.text.DecimalFormat;
public class tetr
{
public static String padDoubleLeft(Double d, int totalDigit,int fractionalDigit) {
String str="";
DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setMinimumFractionDigits(fractionalDigit);
decimalFormat.setMaximumFractionDigits(fractionalDigit);
decimalFormat.setGroupingUsed(false);
decimalFormat.setMaximumIntegerDigits(totalDigit - fractionalDigit - 1);
decimalFormat.setMinimumIntegerDigits(totalDigit - fractionalDigit - 1);
str=decimalFormat.format(d);
/**
* 去掉前面的0(比如000123213,最后输出123213)
*/
while(str.startsWith("0"))
{
str=str.substring(1);
}
return str;
}
public static void main(String[] args)
{
String str="";
Double d=1.7949E+7;
/**d表示你要转化的数字*/
/**50表示总共要留多少位数,
* 2表示小数位数,
* 如果不知道总共留多少位,可以给大一些(比如此处为50)
* 一般情况下,总位数不会超过50,除非客户有这个需要
* 小数按照客户要求来作
* */
str=padDoubleLeft(d,50, 2);
System.out.println(str);
}
}

 

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
如何在MySQL中刪除或修改現有視圖?如何在MySQL中刪除或修改現有視圖?May 16, 2025 am 12:11 AM

todropaviewInmySQL,使用“ dropviewifexistsview_name;” andTomodifyAview,使用“ createOrreplaceViewViewViewview_nameAsSelect ...”。 whendroppingaview,asew dectivectenciesanduse和showcreateateviewViewview_name;“ tounderStanditSsstructure.whenModifying

MySQL視圖:我可以使用哪些設計模式?MySQL視圖:我可以使用哪些設計模式?May 16, 2025 am 12:10 AM

mySqlViewScaneFectectialized unizedesignpatternslikeadapter,Decorator,Factory,andObserver.1)adapterPatternadaptSdataForomDifferentTablesIntoAunifiendView.2)decoratorPatternenhancateDataWithCalcalcualdCalcalculenfields.3)fieldfields.3)

在MySQL中使用視圖的優點是什麼?在MySQL中使用視圖的優點是什麼?May 16, 2025 am 12:09 AM

查看InMysqlareBeneForsImplifyingComplexqueries,增強安全性,確保dataConsistency,andOptimizingPerformance.1)他們simimplifycomplexqueriesbleiesbyEncapsbyEnculatingThemintoreusableviews.2)viewsEnenenhancesecuritybyControllityByControllingDataAcces.3)

如何在MySQL中創建一個簡單的視圖?如何在MySQL中創建一個簡單的視圖?May 16, 2025 am 12:08 AM

toCreateAsimpleViewInmySQL,USEthecReateaTeviewStatement.1)defitEtheetEtheTeViewWithCreatEaTeviewView_nameas.2)指定usethectstatementTorivedesireddata.3)usethectStatementTorivedesireddata.3)usetheviewlikeatlikeatlikeatlikeatlikeatlikeatable.views.viewssimplplifefifydataaccessandenenanceberity but consisterfort,butconserfort,consoncontorfinft

MySQL創建用戶語句:示例和常見錯誤MySQL創建用戶語句:示例和常見錯誤May 16, 2025 am 12:04 AM

1)foralocaluser:createUser'localuser'@'@'localhost'Indidendify'securepassword'; 2)foraremoteuser:creationuser's creationuser'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Rocaluser'@'localhost'Indidendify'seceledify'Securepassword'; 2)

在MySQL中使用視圖的局限性是什麼?在MySQL中使用視圖的局限性是什麼?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)他們不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinsOrsubqueries.2)他們canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

確保您的MySQL數據庫:添加用戶並授予特權確保您的MySQL數據庫:添加用戶並授予特權May 14, 2025 am 12:09 AM

porthusermanagementinmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

哪些因素會影響我可以在MySQL中使用的觸發器數量?哪些因素會影響我可以在MySQL中使用的觸發器數量?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)複雜的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

北端:融合系統,解釋
1 個月前By尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
4 週前By尊渡假赌尊渡假赌尊渡假赌
<🎜>掩蓋:探險33-如何獲得完美的色度催化劑
2 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。