For C# I'm trying to find what the best variable is to print out a large (trillions) number to 2 decimal places. However, I can't find the variable that works without rounding the second decimal. My best option right now seems to be the double variable, but it is rounding the second decimal.
Well, if you add a reference to system.numerics and then add using system.numerics to the list of using statements, you could use BigInteger @int = new BigInteger(); and then assign a value to "int".
I'm not sure what you mean with the system.numerics. My code looks like this right now: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication101 { class Program { static void Main(string[] args) { double i = 16741848020477.05; Console.WriteLine(i); } } }
The .05 keeps changing to .1
I'll make a screenshot.
Add the reference as shown in the picture
I can't seem to find it on my VS
Also, would double be the correct variable to use? Or would something like decimal would be?
Basically, I'm trying to find the best data type to use for that specific number.
Well, let me go through the list of variables in VS really quick and see what the best one would be.
Thank you. I'm confused since the decimal keeps changing.
I believe the variables are: short, int, long, byte, ushort, uint, ulong, float, double, decimal, char, string, bool
Well, you could always make it a string, unless you need to use it later in some sort of equation or something.
Yeah, I was thinking about that. I'm not sure if I can though since I was told it needed to be a data type. However, I can't seem to find the data type that prints it correctly
Also, when I tried making it anything other than a double or string, it told me it couldn't convert a double to whatever I was trying to use. So, I guess string would maybe be the best choice.
Hmmm, I see. Thank you, I'll try and go with string.
Okay, but I'm going to see if I can find a way to prevent it from rounding in case strings aren't acceptable.
Thank you, I appreciate all the help for this
The question was this: If you were tasked with keeping track of the US Government's national debt to the nearest penny, what data type would you use? Explain how you decided this was the best choice. You think string would best fit as the answer?
Probably. Because I couldn't find another way to do it.
I see, thank you
So, was I right? :3
Haha, haven't gotten a response yet. I believe so though :P
Join our real-time social learning platform and learn together with your friends!