Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Converts 14,159,431.12 or 14.159.431,12 into 14159431.12
- /// </summary>
- /// <param name="this"></param>
- /// <returns></returns>
- public static decimal FromPriceToDecimal(this string @this)
- {
- if (@this == null) return 0;
- NumberStyles style;
- CultureInfo provider;
- style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
- provider = new CultureInfo("en-US");
- #region encontrar e remover pontos marcadores maiores que decimal
- Regex rx = new Regex(@"\.", RegexOptions.Compiled | RegexOptions.IgnoreCase);
- MatchCollection matches = rx.Matches(@this);
- if (matches.Count > 1)
- {
- for (int i = matches.Count; i > matches.Count - 1; i--)
- {
- @this = @this.Remove(matches[i - 1].Index, 1);
- }
- }
- #endregion
- var formatedDecimal = Regex.Replace(@this, "[^0-9/.]", "");
- return decimal.Parse(formatedDecimal, style, provider);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement