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;