D
D
DiSay2020-06-04 18:07:48
C++ / C#
DiSay, 2020-06-04 18:07:48

How to make reductions of large numbers in unity?

I'm making a game and I need 1000 to be displayed as 1k millions 1M etc. I've searched all over the place and still don't understand how to do it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-06-04
@firedragon

As an example, append the output format

public class DoubleConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return "";

            var doubleValue = (double)value;
            return $"{doubleValue}";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var strValue = value as string;
            if (string.IsNullOrEmpty(strValue))
                return 0;

            if (double.TryParse(strValue, out var resultDecimal))
            {
                return resultDecimal;
            }
            return 0;
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question