Gabriel39 commented on issue #15307:
URL: https://github.com/apache/doris/issues/15307#issuecomment-1423834674

   > I have encountered the same problem with version 1.2.1, but version 1.2.0 
is normal. (在1.2.1版本中遇到相同问题,在1.2.0中没问题)
   > 
   > I found that it may be related to the odd and even number of digits to be 
reserved. That is, version 1.2.1. If the second decimal digit reserved is an 
even number, it will be discarded; If it is odd, the normal function is 
rounding (我发现可能跟要保留的第几位数的奇偶数有关。即1.2.1版本,如果保留的第二位小数是偶数,则舍弃;如果是奇数则正常功能即四舍五入) 
![图片](https://user-images.githubusercontent.com/65714358/213093908-d062e533-e6a6-4755-9170-ea7bc9cccedf.png)
 select round(46.215,2), round(46.225,2), round(46.235,2), round(46.245,2), 
round(46.255,2), round(46.265,2), round(46.275,2), round(46.285,2), 
round(46.295,2)\G;
   
   Hi @Mint-Boy-He , actually, function `round` doesn't have a reasonable 
behavior before. This is because DECIMAL type in Doris is not a real decimal so 
we cannot provide a precise value after `found`. Fortunately we have DECIMALV3 
since 1.2.1 which can provide a precise value for functions like `round`. So 
you can just use DECIMALV3 if you need a precise rounded value.
   
   For example,
   1. CREATE TABLE `decimal_table` (`col` DECIMALV3(10, 4) NOT NULL COMMENT ''  
   ) distributed by hash(`col`) buckets 1      
properties("replication_num"="1");
   2. insert into decimal_table values (46.215), (46.225), (46.235), (46.245);
   3. select col, round(col, 2) from decimal_table;
   
   And then we got results below:
   
![image](https://user-images.githubusercontent.com/37700562/217762638-7199fd0f-ba42-4f30-83b7-08e332220c5b.png)
   
   If you have any problem using DECIMALV3, feel free to tell me and I'm glad 
to offer your help


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to