sqlwrite only writes 6 digits to Access Database
조회 수: 10 (최근 30일)
이전 댓글 표시
I'm trying to write an Excel date code to an Access database in the format: 44798.6912268518
but when I open the Access database, the date code is written as 44798.7.
Is there a way to write more than 6 digits to an Access database without changing the data type to a string?
댓글 수: 0
답변 (1개)
Rahul
2024년 11월 7일 9:48
I understand that currently while accessing data from database, you are obtaining the number in a short format. You can consider defining 'format long' before writing the data which can consider approximately 15 decimal places for double-precision numbers. Here is an example:
% I have taken 'conn' and 'tablename' as variables for connection with the database, can be adjusted
% Set the display format to long
format long
dateCode = 44798.6912268518;
data = table(dateCode, 'VariableNames', {'yourFieldName'});
sqlwrite(conn,tablename,data)
Another approach can be to use the 'vpa' function provided by the Symbolic Math Toolbox which enables to define number of significant decimal places required. Here is an example:
dateCode = vpa(44798.6912268518, 30); % Here I have taken 30 as an example for required decimal places
data = table(dateCode, 'VariableNames', {'yourFieldName'});
sqlwrite(conn,tablename,data)
You can refer to the following MathWorks documentations to know more about these functions:
Hope this helps! Thanks.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!