lizc9 opened a new issue, #6289:
URL: https://github.com/apache/paimon/issues/6289

   ### Search before asking
   
   - [x] I searched in the [issues](https://github.com/apache/paimon/issues) 
and found nothing similar.
   
   
   ### Paimon version
   
   1.2.0
   
   ### Compute Engine
   
   flink 1.20
   
   ### Minimal reproduce step
   
   1. insert float 175.26562 value to postgresql table
   2. start paimon flink cdc table sync
   
   ### What doesn't meet your expectations?
   
   I have seen that someone has fixed the float type conversion problem 
(#5263), but this method is not universal and still results in errors for some 
special values. For example: float 175.26562 will be converted to 175.26563 
according to the following code, so it will report an error. The expected value 
is the same.
   ```java
   double d = Double.parseDouble(s);
   if (d == ((float) d)) {
       return (float) d;
   } else {
       // Compatible canal-cdc
       Float f = Float.valueOf(s);
       String floatStr = f.toString();
       if (s.contains(".") && !s.contains("E")) {
           int decimal = s.length() - s.indexOf(".") - 1;
           floatStr = String.format("%." + decimal + "f", f);
       }
       if (!floatStr.equals(s)) {
           throw new NumberFormatException(
                   s + " cannot be cast to float due to precision loss");
       } else {
           return f;
       }
   }
   ```
   
   change to:
   ```java
   if (!String.valueOf(ff).equals(String.valueOf(d))) {
       throw new NumberFormatException(
               s + " cannot be cast to float due to precision loss");
   } else {
       return f;
   }
   ```
   
   <img width="967" height="270" alt="Image" 
src="https://github.com/user-attachments/assets/1b7ccf89-f8b8-4b18-b9d1-d3b8a7f48ce9";
 />
   
   
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!


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