I have a problem! | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

I have a problem!

I want to SUM two double Point numbers! double a = 4.0; double b = 4.0; Console.WriteLine(a+b); The result is 8! I want the result like this 8.0! Can someone help pls!

7th Dec 2016, 4:21 PM
Mitran Constantin Bogdan
Mitran Constantin Bogdan - avatar
1 Resposta
0
You can use Standard Numeric Format Strings (complex name for something rather simple!) double a = 4.0; double b = 4.0; Console.WriteLine((a+b).ToString("N1")); We're telling the compiler to first add a and b (8) and use the Numeric Formatting (N stands for Number and 1 for the amount of decimal places) to display: 8.0 You can learn more about this here: https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx
7th Dec 2016, 4:34 PM
Le Patron
Le Patron - avatar