zoukankan      html  css  js  c++  java
  • 类型转换

      public static float Str2Money(string value)
            {
                if (string.IsNullOrEmpty(value))
                {
                    return 0f;
                }
                else
                {
                    value = value.Replace(",", "");
                    return float.Parse(value);
                }
            }


            /// <summary>
            ///
            /// </summary>
            /// <param name="value"></param>
            /// <returns></returns>
            public static string Money2Str(float value)
            {
                return value.ToString("N");
            }


            /// <summary>
            ///
            /// </summary>
            /// <param name="value"></param>
            /// <returns></returns>
            public static DateTime Str2Date(string value)
            {
                if (string.IsNullOrEmpty(value))
                    return DateTime.MinValue;
                else
                {
                    DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
                    dtFormat.ShortDatePattern = "dd-MM-yy";
                    return Convert.ToDateTime(value, dtFormat);
                }
            }



            public static string Date2String(DateTime value)
            {
                if (value == DateTime.MinValue)
                    return string.Empty;
                else
                    return value.ToString("dd-MM-yy");
            }



            /// <summary>
            ///
            /// </summary>
            /// <param name="value"></param>
            /// <returns></returns>
            public static int Str2Int(string value)
            {
                if (string.IsNullOrEmpty(value))
                    return 0;
                else
                    return int.Parse(value);
            }


            /// <summary>
            ///
            /// </summary>
            /// <param name="value"></param>
            /// <returns></returns>
            public static Guid? Object2Guid(object value)
            {
                if (value == System.DBNull.Value)
                {
                    return null;
                }
                else
                {
                    return new Guid(value.ToString());
                }
            }


            /// <summary>
            ///
            /// </summary>
            /// <param name="value"></param>
            /// <returns></returns>
            public static string Object2Sting(object value)
            {
                if (value == System.DBNull.Value)
                {
                    return string.Empty;
                }
                else
                {
                    return value.ToString();
                }
            }

  • 相关阅读:
    1988-B. 有序集合
    1987-A. 集训队选拔
    1964-NP
    1963-带妹子去看电影
    1962-Fibonacci
    1961-计算机基础知识大赛 2 (new)
    TCP/IP协议详解 卷一:协议 18章、TCP连接的建立与终止
    3、剑指offer--从尾到头打印链表
    2、剑指offer--替换空格
    1、剑指offer--二维数组中查找
  • 原文地址:https://www.cnblogs.com/GreenGrass/p/2921814.html
Copyright © 2011-2022 走看看