Get the decimal part from a double

后端 未结 18 864
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 06:47

I want to receive the number after the decimal dot in the form of an integer. For example, only 05 from 1.05 or from 2.50 only 50 not 0.50

18条回答
  •  暖寄归人
    2020-11-29 07:24

        public static string FractionPart(this double instance)
        {
            var result = string.Empty;
            var ic = CultureInfo.InvariantCulture;
            var splits = instance.ToString(ic).Split(new[] { ic.NumberFormat.NumberDecimalSeparator }, StringSplitOptions.RemoveEmptyEntries);
            if (splits.Count() > 1)
            {
                result = splits[1];
            }
            return result;
        }
    

提交回复
热议问题