# The precision of the decimal number of the Cplex

I have faced a little weird problem when I use Cplex to solve my test problem. Basically, some of my data are float numbers up to three decimal numbers (For instance, 0.627). But, when I print out the model using the exportModel command, I noticed that Cplex converts all the float numbers to numbers with much more degree of precision (For example, 0.627 to 0.626999974250793). As a result of this, Cplex gives me the wrong optimal solution. I'd be grateful if you could let me know what is the cause of this error and how I can prevent this convergence?

I should note that I use Concert technology C++.

• 0.627 cannot be stored exactly in IEEE-754 floating point arithmetic. The decimal representation of the value that can actually be stored is 0.62699997425079345703125 . So numerically, everything is ok.
– T_O
Jun 8, 2021 at 15:22
• In what way is the optimal solution wrong (and by how much)?
– prubin
Jun 8, 2021 at 15:45
• Basically, the optimal objective value for the test instance I am dealing with, reported as 222 (It is a maximization problem). But, when I call Cplex, it reports 224 as the optimal objective value. When I use the original data that I have (with three decimal floating point) and verify the value of the decision variables given by Cplex, it gives the objective value of 126 !!! I also multiply all the float numbers by 1000. This time Cplex gives 223 as the optimal value
– Sam
Jun 8, 2021 at 15:54
• I just multiply all the float numbers by a very big number (100000000000), surprisingly Cplex reports the right optimal value (222)
– Sam
Jun 8, 2021 at 15:59
• I am still a bit confused. Is there any way to systematically avoid these sort of errors?
– Sam
Jun 8, 2021 at 16:00

instead of exporting into a .lp you could export into a .sav filre and then you won't face those rounding issues.

SAV is a binary file format specific to CPLEX. This format is efficient for fast reading and writing of models and associated basis information. For example, it can effectively reduce read and write time for problems that are solved repetitively.

Tip: CPLEX includes the basis in a SAV file only if the problem currently in memory has been optimized and a basis exists.

This format also offers the advantage of being numerically accurate (to the same degree as your platform) in contrast to text file formats that may lose numerical accuracy. In other words, it provides a greater degree of precision in data. However, since a SAV file is binary, you cannot read nor edit it with your favorite text editor.

• For the sake of clarity, would you mean that if I read the data from a .sav file, Cplex won't do conversions issues and I will work with exactly the same data I provided to it?
– Sam
Jun 8, 2021 at 16:11
• Yes that's it. Right Jun 8, 2021 at 16:23
• Great, many thanks !
– Sam
Jun 9, 2021 at 14:52