himadripal commented on code in PR #7179:
URL: https://github.com/apache/arrow-rs/pull/7179#discussion_r2021953487


##########
arrow-cast/src/parse.rs:
##########
@@ -850,7 +850,16 @@ fn parse_e_notation<T: DecimalType>(
     }
 
     if exp < 0 {
-        result = result.div_wrapping(base.pow_wrapping(-exp as _));
+        let result_with_scale = result.div_wrapping(base.pow_wrapping(-exp as 
_));
+        let result_with_one_scale_up =
+            result.div_wrapping(base.pow_wrapping(-exp.add_wrapping(1) as _));

Review Comment:
   `exp` in the `parse_e_notation` method is being overriden couple of times 
based on which direction the decimal needs to shift and if the original string 
has fractional in it. ( i.e 1.23e-2 has 2 fractional digits).
   
   before this check, `exp` represents number of digits to be removed or added. 
In this case, exp = -3 
   
   now, result_with_scale = 12
   result_with_one_scale_up=123
   
   to round up or down, we need to capture what is the digit next to last digit 
in the result, in this case 3. How we get it is  = (123 -  12* 10 )
   
   if rounding_digit >=5 then we add +1 to the result
   else result remains intact.
   
   ![Image 3-31-25 at 5 30 
PM](https://github.com/user-attachments/assets/3e80b377-ba81-4c74-a670-8b8a28dc16db)
   I added a debugging screenshot to help understand it more.
   
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to