sqlwrite round up number when use in stand alone app
2 views (last 30 days)
I have weird behavior with sqlwrite function when compile as standalone application. I use sqlwrite function to write float number to oracle database using odbc connection. Database is already set corresponding column type to be float(126). When I use function in appdesigner and test in desktop is work fine. Data that write to database was float example I write 123.45 --> database show 123.45.
But when I compile as .exe and test I seem it always round up weirdly. 1.234 --> 1, 14.123 --> 10, 241.123 --> 200. Don't know why it have different output between desktop and .exe.
Anyone have experience?
Prathamesh on 22 Aug 2023
I understand that you are facing issue with “sqlwrite” function.
It depends on the column type, precision and scale defined, because of which the digits are rounded off or truncated. You can try to set precision of 38 and scale of 16 (or depending on the length of data) for the specific column to fit the data so that it will not get rounded off or truncated.
For example, you can try:
>> execute(conn,'CREATE TABLE testnumeric(COL1 numeric(38,16))')
>> T = sqlread(conn,'testnumeric')
It will give the desired output.
You can also store the data into string in the database and then convert back to float or double in the implementation.
Steven Lord on 23 Aug 2023
I'm guessing that you're computing the values that are being rounded from the input arguments to your application. Is that correct? If so are you taking into account the first point in the "Using a MATLAB File You Plan to Deploy" section on this documentation page?
"The input arguments you pass to your executable from a system prompt are received as character vector input. Thus, if you expect the data in a different format (for example, double), you must first convert the character vector input to the required format in your MATLAB code. For example, you can use STR2NUM to convert the character vector input to numerical data." [Emphasis added.]