how to remove decimals

266 ビュー (過去 30 日間)
Fire
Fire 2011 年 7 月 27 日
コメント済み: yogan Sganzerla 2021 年 6 月 6 日
Hello all,
I have data with secons just for example
1.05, 2.10, 4.08, 5.09 ... etc.
I really dont want the decimal points in seconds. I just want say for above example like 1, 2, 4, 5 etc... I want to remove the decimal points completely. Can anyone suggest what code I have to use..
Thanks in advance
  1 件のコメント
Shreesha Subrahmanya
Shreesha Subrahmanya 2021 年 4 月 13 日
x =[1.05, 2.10, 4.08, 5.09 ];
y =floor(x)

サインインしてコメントする。

回答 (5 件)

Oleg Komarov
Oleg Komarov 2011 年 7 月 27 日
  1 件のコメント
Go Detroit Lions
Go Detroit Lions 2018 年 11 月 27 日
Dude, I have to testify, everything you answer is on point the right answer!! Thanks!!

サインインしてコメントする。


Daniel Shub
Daniel Shub 2011 年 7 月 27 日
doc round
  4 件のコメント
Qaiser khan Bozdar
Qaiser khan Bozdar 2020 年 2 月 2 日
Worked like a pro for my code.I used it as " i = uint16(clock) ". Thank you
Walter Roberson
Walter Roberson 2020 年 2 月 2 日
Watch out: the uint*() and int*() calls round() values.

サインインしてコメントする。


Adi Mico
Adi Mico 2011 年 7 月 27 日
a= [2.02 3.14 0.13];
b=round(a);
Hope this can help you.

Daniel Shub
Daniel Shub 2011 年 7 月 27 日
double(int64(10.2))
  1 件のコメント
Jan
Jan 2011 年 7 月 27 日
int64(10.6) => 11. The OP did not specify if rounding or truncation is wanted.

サインインしてコメントする。


yogan Sganzerla
yogan Sganzerla 2021 年 6 月 4 日
I have a similar question...
my vector in matlab is V = [1;2;3;4] and I would like to create a table with this vector in SQL.
However, what is appearing in SQL is V = [1.000000000;2.000000000;3.000000000;4.000000000;5.000000000].
I wanna the vector to be without the decimal part IN SQL.
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 6 月 5 日
When you create the table() for use with sqlwrite(), https://www.mathworks.com/help/database/ug/database.odbc.connection.sqlwrite.html then as an experiment, store an integer data type into the table entry. For example,
t = table(uint16(V), 'VariableNames', 'Var1');
and then sqlwrite() that.
This assumes that the table does not already exist in SQL. If the table already exists, then you might need to change the schema for that variable to one of the int datatypes; https://docs.microsoft.com/en-us/sql/t-sql/data-types/int-bigint-smallint-and-tinyint-transact-sql?view=sql-server-ver15
yogan Sganzerla
yogan Sganzerla 2021 年 6 月 6 日
Thank you for your replay Walter, however this is not what I am looking for....
I already know how to create a table im Malab and how to import in SQL. My problem is regarding the variable type in SQL. Even using uint16(V) the table in SQL has been saved asV = [1.000000;2.0000000;...5.0000000] as you can see in the photo below
%% DECLARATION
theDataBaseName = '****';
theDataBaseUser = '****';
theDataBasePassword = '****';
theDataBaseDriver = 'org.mariadb.jdbc.Driver';
theDataBaseIP = '****';
tablename = 'Test';
%% START PROGRAM
theConnection = database(theDataBaseName, theDataBaseUser, theDataBasePassword, theDataBaseDriver, strcat('jdbc:mysql://',theDataBaseIP,'/'));
id =1:5;
id = id';
sending = table(uint16(id),'id')
sqlwrite(theConnection,tablename,sending)
close(conn)
The photo below shows the variable Sending and id in MATLAB
and here how it was saved in SQL.
As you can see, appears the decimal part as it was saved in SQL as decimal(38,16) instead of bigint(20) for example.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by