如何将文本更改为MySQL中的小数?

发布于 2025-01-31 03:45:05 字数 257 浏览 4 评论 0原文

我的MySQL数据集中有很多数据类型文本的值(以前百分比)。

它们看起来都像24.05、0.25、46.3、5.2等。

我想将它们转换为数据类型,以便我以后将它们乘以它们,以便通过将这些百分比乘以0.01。

我尝试过,

ALTER TABLE table_name
MODIFY COLUMN col_name binary/decimal/int.

我不知道该怎么做。

谢谢你!

I have plenty of values(previously percentages) of data type text in my MySQL dataset.

They all look like 24.05, 0.25, 46.3, 5.2, etc.

I want to convert these to a data type that will allow me to multiply them later on so that I can make these percentages into complete decimals by multiplying by 0.01.

I've tried

ALTER TABLE table_name
MODIFY COLUMN col_name binary/decimal/int.

I can't figure out how to do this though.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人练习一个人 2025-02-07 03:45:06

您可以使用十进制 datatype。

DECIMAL(Precision, Scale)

我将sakila db作为示例如图所示。

ALTER TABLE `sakila`.`film` 
CHANGE COLUMN `rental_rate` `rental_rate` DECIMAL(5,2) NOT NULL DEFAULT '4.99';

这意味着租金总共可以承担5位数字。小数点之后,其中两个出现在右边

You may use the DECIMAL datatype.

DECIMAL(Precision, Scale)

I used the sakila db as an example as shown;

ALTER TABLE `sakila`.`film` 
CHANGE COLUMN `rental_rate` `rental_rate` DECIMAL(5,2) NOT NULL DEFAULT '4.99';

meaning the rental rate can assume a total of 5 digits. two of them appearing to the right after the decimal point

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文