csharp: Double Convert To String_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > csharp: Double Convert To String

csharp: Double Convert To String

 2015/3/12 18:58:48  ?Geovin Du Dream Park?  程序员俱乐部  我要评论(0)
  • 摘要:///<summary>//////</summary>///<paramname="fl"></param>///<returns></returns>privatestringConvertFloatToString(floatfl){stringstr=string.Empty;str=String.Format("{0:N2}",fl);returnstr;}///<summary>
  • 标签:ARP
class="brush:csharp;gutter:true;">/// <summary>
        /// 
        /// </summary>
        /// <param name="fl"></param>
        /// <returns></returns>
        private string ConvertFloatToString(float fl)
        {
            string str = string.Empty;
            str = String.Format("{0:N2}", fl);
            return str;
        }
        /// <summary>
        /// 字符串转double
        /// </summary>
        /// <param name="fl"></param>
        /// <returns></returns>
        private double ConvertStringToDouble(string fl)
        {
            double str = 0.00;

            try
            {
                if (double.TryParse(fl, out str))//对就输出正确数据
                {

                }
                else
                {
                    MessageBox.Show("数据类型不对,请检查一下!");
                }

            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                str = 0.00;
            }
            return str;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fl"></param>
        /// <returns></returns>
        private string ConvertDoubleToString(double fl)
        {
            string str = string.Empty;

            try
            {
                str = string.Format("{0:C}", fl);
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                str = "¥0.00";
            }
            return str;
        }
        /// <summary>
        ///涂聚文 geovindu  
        /// </summary>
        /// <param name="fl"></param>
        /// <returns></returns>
        private string ConvertDecimalToString(decimal fl)
        {
            string str = string.Empty;
            try
            {
                if (fl > 0)
                {
                    str = string.Format("¥{0:N2}", fl);
                }
                else
                {
                    str = "¥0.00";
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                str = "¥0.00";
            }
            return str;
        }


打印格式:

            StringFormat format = new StringFormat(); //对齐方式StringFormatFlags.DirectionRightToLeft  //:靠右对齐 涂聚文注
            format.FormatFlags = StringFormatFlags.DirectionRightToLeft;
            format.Trimming = StringTrimming.Word;
            format.Alignment =StringAlignment.Near;

            StringFormat formatc = new StringFormat(); //DisplayFormatControl StringFormatFlags.MeasureTrailingSpaces  //负数的格式:靠右对齐
            formatc.Trimming = StringTrimming.Word;
            formatc.Alignment = StringAlignment.Far;
            formatc.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;  

 

上一篇: 帮传统行业转型 微信发布行业解决方案 下一篇: 没有下一篇了!
发表评论
用户名: 匿名