版本号浮动,小数或双 [英] Version Numbers float, decimal or double

查看:258
本文介绍了版本号浮动,小数或双的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件管理系统,文件可以有多个版本。每个版本都保存,用户可以查看历史版本。

I have a document management system where documents can have multiple versions. Each version is saved and users can view version history.

我想知道的是:我应该使用的版本号是什么数据类型?小数,float或double?我使用.NET和C#。

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#.

版本号开始的 0.1 和每个出版的主要的版本将被舍入到下一个整数。即 0.4 进入 1.0 1.3 进入 2.0 等。

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.

在版本号点击 0.9 轻微的版本中加入我想数转至 0.10 不是 1.0 ,当我添加到它。这是最大的问题。

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.

任何建议都是AP preciated。

Any suggestions are appreciated.

感谢。

推荐答案

System.Version

这已经存储在不同的部位,用$ P $处理psenting它作为一个字符串(修订和构建组件仅用于显示,如果他们不为零,所以他们无关,以你的情况并不重要)和(最好全部)已经理解其他.NET开发人员,并不会引起混淆(如果我看到一些使用,这不是一个版本号的 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 why Version 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:

public static Version IncrementMajor(this Version ver)
{
  return new Version(ver.Major + 1, 0);
}
public static Version IncrementMinor(this Version ver)
{
  return new Version(ver.Major, ver.Minor + 1);
}

这篇关于版本号浮动,小数或双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆