使用什么:变量的十进制或浮点数 [英] what to use: decimal or float for a variable

查看:77
本文介绍了使用什么:变量的十进制或浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在以下代码中使用了什么:





float v_tax = Convert.ToInt32(ds。表[0] .Rows [i] [tax]);





''tax''是一个float数据类型保持12.55作为数据。

在运行时期间,变量v_tax的值为13而不是12.55。



任何人都可以指导我。

问候。

I would like to know what exactly to use in my following code:


float v_tax = Convert.ToInt32(ds.Tables[0].Rows[i]["tax"]);


The ''tax'' is a float datatype holding 12.55 as data.
During run time the variable v_tax is having value as 13 instead of 12.55.

Can anyone please guide me.
Regards.

推荐答案

你好,



使用 Convert.ToSingle方法 [ ^ ]而不是 Convert.ToInt32 方法:

Hi,

Use the Convert.ToSingle method[^] instead of the Convert.ToInt32 method:
float v_tax = Convert.ToSingle(ds.Tables[0].Rows[i]["tax"]);


精度是double和float之间的主要区别。 Decimal具有更高的浮动精度。

尝试使用float。
Precision is the main difference between double and float. Decimal has more precision that float.
Try using float.


这篇关于使用什么:变量的十进制或浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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