You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
964 B

  1. using Shentun.Utilities;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace System
  6. {
  7. public static class ConvertExtensions
  8. {
  9. public static decimal ToDecimal(this string value)
  10. {
  11. decimal data = 0.0m;
  12. if (value.ToUpper().Contains("E"))
  13. {
  14. data = Convert.ToDecimal(Decimal.Parse(value.ToString(), System.Globalization.NumberStyles.Float));
  15. }
  16. else
  17. {
  18. data = Convert.ToDecimal(value);
  19. }
  20. return data;
  21. }
  22. public static int ToAge(this DateTime birthdate)
  23. {
  24. DateTime now = DateTime.Now;
  25. int age = now.Year - birthdate.Year;
  26. if (now.Month < birthdate.Month || (now.Month == birthdate.Month && now.Day < birthdate.Day))
  27. {
  28. age--;
  29. }
  30. return age < 0 ? 0 : age;
  31. }
  32. }
  33. }