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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











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

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.

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())

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.

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.

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 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.

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.
