0

Newbie here in C#..

I am creating a calculator, and would like to display my numbers through UI text elements. Problem is that i want to limit my number to say, 4 decimals like 10.4812

I tried with Tostring("F4"), which works, but then when i have a round number like 12, it will display "12.0000", which is ugly.

What would be the simplest way to achieve this ? I thought of complicated ways, like converting my ui element.text into a char array, then detecting the ".", counting 4 digits and removing the rest, but that sounds crazy maybe ?

It has happened many times that i was trying too insane things when something simple was existing, so i thought it was worth asking :D.

Thanks in advance!

Gynko
  • 75
  • 1
  • 8

1 Answers1

0

Maybe Math.Round(10.48124812, 4) helps you. The second argument (4) stands for the number of digits after the dot.

See: https://msdn.microsoft.com/de-de/library/75ks3aby(v=vs.110).aspx

gooleem
  • 334
  • 3
  • 9