Solution to Oracle number type query precision loss

Source: Internet
Author: User

When querying the Oracle number type, you may encounter errors in precision. The following describes a solution to the loss of the Oracle number type query accuracy for your reference.

I. The Oracle number type query requirement requires that the value of a field be found and then the second digit after the decimal point is kept
// If you use the following method to obtain a number from ResultSet, and the number is greater than 40000, the obtained data will be inaccurate

 
 
  1. floatzcxxhj+=rss.getFloat(3); 

// If double is used, no problem occurs.

 
 
  1. double zcxxhj+=rss.getDouble(3); 

// Rounded to the second digit after the decimal point

 
 
  1. list.add(new BigDecimal(zcxxhj).setScale(2, BigDecimal.ROUND_HALF_UP)); 


2. If the Oracle number type query requires that the number retrieved from the database be retained to the second digit after the decimal point, it is then directly displayed on the front-end.
We can use the following query method:
Example:

 
 
  1. Select fpdm,
  2. Fphm,
  3. Fkdw,
  4. To_char (kprq, 'yyyy-mm-dd '),
  5. To_char (xxhj, 'fm9999999999990. 00 '),
  6. Decode (fpzt, '1', 'positive pass', '2', 'Red pass', '3', 'invalid pass ')
  7. From wskp_fpkj_zbxx_111000861071
  8. Where 11 = 1
  9. And nssbh = '000000'

The xxhj is of the number type. We can use to_char (xxhj, 'fm990. 00 '), keep at least two digits after the tree points, three digits before the decimal point, at least one;
Another example is to_char (xxhj, 'fm9990. 123456'), which means to keep at least two digits after the decimal point, at most four digits, four digits before the decimal point, and at least one digit.

3. If you want to add the numbers to be found, keep the last two digits of the small tree.

 
 
  1. double d=rss.getDouble(3)+ rss.getDouble(4);  
  2.  BigDecimal bigDecimal= new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP);  
  3.  beanData.setXxhj(bigDecimal.toString());     

Oracle multi-Table query instance

ORACLE Database Encoding

Use the Oracle to_date () function

Oracle date formatting implementation

Oracle memory structure-SGA

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.