在MySQL的单个列中使用整数和十进制数字(using Whole and Decimal numbers in a single column in mysql)

系统教程 行业动态 更新时间:2024-06-14 16:52:52
在MySQL的单个列中使用整数和十进制数字(using Whole and Decimal numbers in a single column in mysql)

我是音乐评论家,我想建立我的网站。 我已经在mysql中创建了一个数据库,其中有一列用于评级。 以下是可能性:10,9.5,9,8.5,8,7.5 ... 1,0.5和0

我可以使用什么样的柱子,现在我选择DECIMAL值为:3,1

问题是,当我输入9时,它返回9.0 ...有没有办法在列中存储整数和十进制数?

I'm a music reviewer and I want to build my website. I've built a database in mysql with a column for the ratings. Here are the possibilities : 10, 9.5, 9, 8.5, 8, 7.5 ... 1, 0.5, and 0

What kind of colum can I use, for now I choose DECIMAL with value of : 3,1

The problem is that when I enter 9, it returns 9.0 ... Is there a way to store Whole and Decimal numbers in a column?

最满意答案

为了格式化显示的数字,你可以用你正在解析mysql结果的任何语言进行那种处理。例如,在PHP中,你只需要转换为浮点并打印它。

$string = '9.0000000'; echo (float)$string;

这将打印'9'。

For formatting the numbers for display, you would do that kind of processing in whatever language you were parsing the mysql results in. In PHP, for example, you would simply cast to a float and print it.

$string = '9.0000000'; echo (float)$string;

This would print '9'.

更多推荐

本文发布于:2023-04-05 12:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/b7a1e26fa787a723227b1728b22279c0.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   十进制数   Decimal   MySQL   column

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!