Home Database Mysql Tutorial 如何使数据库中大的浮点数正常显示,不变成科学计数法显示

如何使数据库中大的浮点数正常显示,不变成科学计数法显示

Jun 07, 2016 pm 03:47 PM
company become how database show normal science count

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

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

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

  比如输入: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);
}
}

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

Samsung will provide displays for Microsoft's MR headsets, and the devices are expected to be lighter and have clearer displays Samsung will provide displays for Microsoft's MR headsets, and the devices are expected to be lighter and have clearer displays Aug 10, 2024 pm 09:45 PM

Recently, Samsung Display and Microsoft signed an important cooperation agreement. According to the agreement, Samsung Display will develop and supply hundreds of thousands of OLEDoS panels for mixed reality (MR) head-mounted devices to Microsoft. Microsoft is developing an MR device for multimedia content such as games and movies. This device is expected to It will be launched after the OLEDoS specifications are finalized, mainly serving the commercial field, and is expected to be delivered as early as 2026. OLEDoS (OLED on Silicon) technology OLEDoS is a new display technology that deposits OLED on a silicon substrate. Compared with traditional glass substrates, it is thinner and has higher pixels. OLEDoS display and ordinary display

PHP connections to different databases: MySQL, PostgreSQL, Oracle and more PHP connections to different databases: MySQL, PostgreSQL, Oracle and more Jun 01, 2024 pm 03:02 PM

PHP database connection guide: MySQL: Install the MySQLi extension and create a connection (servername, username, password, dbname). PostgreSQL: Install the PgSQL extension and create a connection (host, dbname, user, password). Oracle: Install the OracleOCI8 extension and create a connection (servername, username, password). Practical case: Obtain MySQL data, PostgreSQL query, OracleOCI8 update record.

How to handle database connections and operations using C++? How to handle database connections and operations using C++? Jun 01, 2024 pm 07:24 PM

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.

See all articles