版本号 float、decimal 或 double
我有一个文档管理系统,其中文档可以有多个版本。每个版本都会被保存,用户可以查看版本历史记录。
我想知道的是:版本号应该使用什么数据类型?小数、浮点还是双精度? 我使用的是 .NET 和 C#。
版本号从0.1开始,每个发布的主要版本将四舍五入到下一个整数。即 0.4 变为 1.0,1.3 变为 2.0 等。
当版本号达到 0.9< /strong> 并且添加了次要版本,当我添加到它时,我希望数字变为0.10而不是1.0。这是最大的问题。
任何建议表示赞赏。
谢谢。
I have a document management system where documents can have multiple versions. Each version is saved and users can view version history.
What I would like to know is: What datatype should I use for version numbers? Decimal, Float or Double? I'm using .NET and C#.
Version numbers start at 0.1 and each published major version will be rounded to the next whole number. i.e. 0.4 goes to 1.0 and 1.3 goes to 2.0 etc.
When a version numbers hits 0.9 and a minor version is added I would like the number to go to 0.10 not 1.0, when I add to it. This is the biggest issue.
Any suggestions are appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
System.Version
这已经存储了不同的部分,处理将其呈现为字符串(修订和构建组件仅在非零时用于显示,因此它们与您的情况无关)问题)并且(最重要的是)其他 .NET 开发人员已经理解了,并且不会导致混乱(如果我看到某些版本号的使用不是
System.Version
我我会花一些时间尝试找出为什么Version
不足以胜任这项工作,以防万一这被证明很重要并且隐藏着令人讨厌的惊喜。如果它足以胜任这项工作,我'。我会对开发人员这样浪费我的时间感到恼火)。您可以使用扩展方法轻松处理所需的递增方式:
System.Version
This already stores the different parts, deals with presenting it as a string (revision and build components are only used in display if they are non-zero, so their irrelevance to your case doesn't matter) and (best of all) is already understood by other .NET developers, and won't lead to confusion (if I saw some use of a version number that wasn't a
System.Version
I'd spend some time then trying to work out whyVersion
wasn't good enough for the job, in case that proved important and hid a nasty surprise. If it was good enough for the job, I'd be irritated at the developer wasting my time like that).You can deal with the means you want for incrementing easily with extension methods:
两个整数怎么样?一份用于重大修改,一份用于小修改?
How about two integers? One for major and one for minor revisions?
为此创建您自己的数据类型
您还可以添加一个比较器,以便您可以检查两个版本号,例如查看哪个版本号是两个版本号中的最高版本。
编辑
添加比较器逻辑也是为了很好的措施:)
Make your own data type for this
You can also add a comparer so you can check two version numbers to see which one is the highest version of two version numbers for example.
EDIT
Added the comparer logic also for good measure :)
我建议使用两个整数:一个大整数和一个小整数。如果您想要一个变量,您甚至可以将其存储为
major * 1000 +minor
。I would suggest two integers: a major and a minor. You can even store this as
major * 1000 + minor
if you want one variable.小数应该是上面给出的最好的,但正如其他人指出的那样,两个整数会更好。
双精度和浮点数不能准确存储所有十进制值,您不希望您的版本突然变成 1.219999999999999999
Decimal should be the best of the above given, but as other has noted two ints would be better.
Doubles and floats does not accurately store all decimal values, you don't want your version to suddenly be 1.219999999999999999