Tag: numeric

安全地自动从双精度投射到十进制:以下是否安全?

在C#中以下列方式从double转换为十进制是安全的: int downtimeMinutes = 90; TimeSpan duration = TimeSpan.FromHours(2d); decimal calculatedDowntimePercent = duration.TotalMinutes > 0? (downtimeMinutes / (decimal)duration.TotalMinutes) * 100.0m : 0.0m; 如果答案是肯定的,那么不要大惊小怪,我只会标记为已接受。

从文本框值中插入数字(十进制)数据

我对以下问题感到困惑; 我有一个C#(WindowsForms)应用程序,我连接到SQL Server数据库,没有问题INSERT,SELECT,UPDATE ……直到我开始使用数值数据; 这个应用程序的目的是管理员工,他们的合同,工作率,合同期限,每小时费率…并做一些有趣的计算,没有什么魔力 。 基本上,我需要在我的数据库中存储格式为“0000,0000”的一些值(decimal?double?float?)。 在我的数据库中,我已经设置了所有列的表格,我需要这些“000,0000”值为十进制 在我的表单中,我没有为我的文本框指定任何特定属性, 要插入我使用我定义了十进制参数的方法 public void createNewContract(int employeeId, string agency, string role, string contractType, string startDate, string endDate, string lineManager, string reportTo, string costCenter, string functionEng, string atrNo, string atrDate, string prNo, string prDate, string poNo, string poDate, string comments, decimal duration, decimal workRatePercent, string currency, decimal hourlyRate, decimal […]

确定DataColumn是否为数字

有没有比这更好的方法来检查DataTable中的DataColumn是否为数字(来自SQL Server数据库)? Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand(“Get_Some_Data”); DataSet ds = db.ExecuteDataSet(cmd); foreach (DataTable tbl in ds.Tables) { foreach (DataColumn col in tbl.Columns) { if (col.DataType == typeof(System.Single) || col.DataType == typeof(System.Double) || col.DataType == typeof(System.Decimal) || col.DataType == typeof(System.Byte) || col.DataType == typeof(System.Int16) || col.DataType == typeof(System.Int32) || col.DataType == typeof(System.Int64)) { […]