如何设置产品数量的小数值 [英] How to set decimal values for product quantity

查看:83
本文介绍了如何设置产品数量的小数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用c#2010创建windows应用程序,这里我使用产品数量浮点数据类型,在我的c#代码中如何设置产品数量。



I am create windows application using c# 2010, here i using product quantity float datatype, in my c# code how set product quantity.

totqty = Convert.ToInt32(sqldr[0].ToString());







这是我的代码如何更改浮动。任何人都给我一个想法。



我尝试过:



如何设置产品数量的十进制值




this is my code how to change float. Any one give me idea.

What I have tried:

How to set decimal values for product quantity

推荐答案

因此从SQL DataReader返回值 - 这意味着它以数据库中的类型返回。

如果那是FLOAT专栏,那么只需

So the value is being returned from an SQL DataReader - which means it is returned in the type it is in the database.
If that's a FLOAT column, then just
float f = (float) (double) sqldr[0];
double d = (double) sqldr[0];

将起作用,

甚至

will work,
or even

decimal dc = (decimal) (double) sqldr[0];






如果你的数据库正在返回你可以使用的漂浮值





Hi,

If your database is returning float values you can use this


decimal totQuantity = 0;
totQuantity = Convert.ToDecimal(sqldr[0]);
txtQuantity.Text = totQuantity.ToString("N2");  // displaying with 2 decimal points





如果满足您的需求,请告诉我。



谢谢。



Please let me know if this satisfies your need.

Thanks.


这篇关于如何设置产品数量的小数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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