C
C#9mo ago
PELMENIICC

❔ How do I make it to show only 5 digits after comma?

double R = 2.4;
double pi = 3.1415926;
int C = 2;
int D = 4;
double E = 3;
Console.WriteLine("Rādiuss R = " + R);
Console.WriteLine("Riņķa Līnijas Garums = "+ C* pi *R);
Console.WriteLine("Riņķa Laukums = " + pi * R*R);
Console.WriteLine("Lodes laukums = " + D * pi * R*R);
Console.WriteLine("Lodes Tilpums= " + Math.Round (D * pi * R *R*R) / E);
double R = 2.4;
double pi = 3.1415926;
int C = 2;
int D = 4;
double E = 3;
Console.WriteLine("Rādiuss R = " + R);
Console.WriteLine("Riņķa Līnijas Garums = "+ C* pi *R);
Console.WriteLine("Riņķa Laukums = " + pi * R*R);
Console.WriteLine("Lodes laukums = " + D * pi * R*R);
Console.WriteLine("Lodes Tilpums= " + Math.Round (D * pi * R *R*R) / E);
10 Replies
Pobiega
Pobiega9mo ago
Google C# format strings And then give me some pelmeni :p
PELMENIICC
PELMENIICC9mo ago
ight if i will understand this shit xd
Pobiega
Pobiega9mo ago
I'll be at a computer in about 15 min if you can't figure it out:)
PELMENIICC
PELMENIICC9mo ago
ye i would use some help
MODiX
MODiX9mo ago
Pobiega
REPL Result: Success
var number = 56.12312213d;
Console.WriteLine($"Number : {number:F5}");
var number = 56.12312213d;
Console.WriteLine($"Number : {number:F5}");
Console Output
Number : 56.12312
Number : 56.12312
Compile: 602.141ms | Execution: 84.365ms | React with ❌ to remove this embed.
PELMENIICC
PELMENIICC9mo ago
figured it out, basicly i put "var" instead of "int" or "double" and used that $....:F5 went through without errors, idk if thats the correct way, but if it works, it works, right?
Pobiega
Pobiega9mo ago
You don't need var, the important part is the dollar sign and the format string
PELMENIICC
PELMENIICC9mo ago
oh.. lemme try that yes, thanks, what's "var" used for anyways then? i'll post my code if anyone needs it : )
double R = 2.4;
double pi = 3.1415926;
int C = 2;
int D = 4;
double E = 3;



Console.WriteLine("Rādiuss R = " + R);
Console.WriteLine($"Riņķa Līnijas Garums = {C * pi * R:F5}");
Console.WriteLine($"Riņķa Laukums = {pi * R * R:F5}");
Console.WriteLine($"Lodes laukums = {D * pi * R*R:F5}");
Console.WriteLine($"Lodes Tilpums= {(D * pi * R * R * R) / E:F5}");
Console.ReadLine();
double R = 2.4;
double pi = 3.1415926;
int C = 2;
int D = 4;
double E = 3;



Console.WriteLine("Rādiuss R = " + R);
Console.WriteLine($"Riņķa Līnijas Garums = {C * pi * R:F5}");
Console.WriteLine($"Riņķa Laukums = {pi * R * R:F5}");
Console.WriteLine($"Lodes laukums = {D * pi * R*R:F5}");
Console.WriteLine($"Lodes Tilpums= {(D * pi * R * R * R) / E:F5}");
Console.ReadLine();
Pobiega
Pobiega9mo ago
var is a variable declaration with "type inference". it means, take the type on the right side so var name = "Steve"; will be a string, because "Steve" is a string. var x = 5; will be an int variable.
Accord
Accord9mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.