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();
                }
            }

  • 相关阅读:
    查看jvm的cg情况
    什么是json
    httpclient工具类
    mysql 优化思路(1)
    mysql存取日期出问题
    springboot和tomcat jar包冲突
    递归
    如何去理解return?
    js BOM判断当前窗口是否最顶层。
    个人笔记,关于ajax 如果没有请求成功不允许再次请求的方法。
  • 原文地址:https://www.cnblogs.com/GreenGrass/p/2921814.html
Copyright © 2011-2022 走看看