✅ Exception thrown: 'System.FormatException' in mscorlib.dll
im just trying to output the data out
67 Replies
What datatype is
monthr
?
Also I recommend using string interpolation fully, that is insanely hard to readmonthr is a string into int
$interpolation
String interpolation is the preferred way of building strings in C#. It is easier to read than concatenation.
For example:
can be written as:
im just doing whatever get me homr
I’ll tr this
double
isnt an integral typeFork
Is there one for double?
Caz I need to output as 01 02 etc
and I also need to use that to cal something too
why even use the
double
type when u r only using it as int
?Can I use Int to cal in double?
like double = Int + 0.5
tho to answer ur question, u could simply use an explicit format
{monthr:00}
but i can explain that better on some other explicit format
#00.00#
#
means its an optional digit, 0
is an explicit digit
so for 1.5
as value u would get 01.50
{monthr:00} work for both Int and double?
yeah
noice lemme try it
Can you answer this tho?
https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings explains this one better
getiing somewhere
in arithmetic u can mix the number types, as long as u wont lose precision,
so
double d = someInt + 0.5;
the someInt
would be first be "upcasted" to a double, and then u simply have only double values thereic ic
thanks
also, u shouldnt use
double
but decimal
for monetary calculationshow to make 10.208328308 abit shorter to 10.50?
no tis okay i actaualy want to round those number later
check out
F
i see it now
thats independent of each other. the "normal" floating point types (
float
and double
) use an someValue * 2^someOtherValue
internally to represent a number,
decimal
uses 10
internally, which is more accurate for monetary calculationsoh alright
u can observe this for example here:
cap5lut
REPL Result: Success
Console Output
Compile: 402.499ms | Execution: 23.600ms | React with ❌ to remove this embed.
m
is the suffix to use the number as decimal
type, just like f
is used for float
I just need to put :m like this right?
I just try to use declare all double into decimal but that would cause some error
if it’s too much trouble then I’m okay with this caz It actually doing what I want them to
yeah, because the numbers u have in code like for example
1.5
are still double
s, u have to use the m
suffix there
eg float someFloat = 1.5;
would not compile either, because 1.5
is a double
value, float someFloat = 1.5f;
would compile tho
and ofc decimal someDecimal = 1.5m;
hm
for some homework or private training project it will be fine to use
double
i assumeYea it’s an assignment
will have to hand it over tmr
hey im sorry to bother you but can you explain why is the final installment is not 10.56 instead it goes down by 0.01 to 10.55
double installment = (loan * interestRate) / (1 - Math.Pow((1 + interestRate), -month));
to be clear this is not my work its what im aiming toward
can u print the value without any formating, as in just
Console.WriteLine(theValue);
?
and the respective $codeTo post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/
$codegif
you know what its already pretty close to what i set out to do
just 0.01 dollar so i dont think its matter
but how do i make it so that whenever i use \t it instead replace the space between the tab with -?
like this
well, that doesnt show anything about the total interest (nor ur screenshot)
ah i can easily do the total
i never really dabbled that much into formating, but most likely u would have to do that manually
but the finall installment why is it 10.55
oh there, didnt notice that one
ic ic i'll do it manaully i just hope that its symmetrical
yea that one i dunno how he do it using the formula he provided
this one but for me its a one and done nvr bring the formula to cal again
well there are methods on
string
for padding,
basically u would do something like string paddedString = yourDoubleValue.ToString("F2").PadRight(17, '-')
to get ur value formatted and then padded on the right side with -
s until it has a length of 17 or greater
https://learn.microsoft.com/en-us/dotnet/api/system.string.padleft?view=net-8.0
https://learn.microsoft.com/en-us/dotnet/api/system.string.padright?view=net-8.0i dont get it but i'll mess around with it
that the last one is different seems more like an imprecision that comes when doing calculations with floating point types
that would be he calculate it multiple time
well, not much i can say besides that when just seeing a screenshot *shrugs*
yea 😂
nope i couldnt do it
if i were to add padding using string then i would have to convert the double into string then i wouldnt beable to use :f to show .00
manual is not an option as well caz its not symmetical
$"{someDouble:blahblah}"
is the same as someDouble.ToString("blahblah")
cap5lut
REPL Result: Success
Result: string
Compile: 315.168ms | Execution: 26.450ms | React with ❌ to remove this embed.
omg
letmme try it
just look at the stuff im trying
doesnt seem to work
i mustve cout wrong
someDouble.ToString("F2").PadRight(17, '-');
returns a string if u just use it like that u just discard the string.
u would do something like,
im sorry, i should have explained that betteralright ty
no its okay
yep its work
ty so much
thats all for now tysm for helping me
i'll be bek in a while to send the final result
oh one more thing
if (number1 > 0 || number2 > 0 || number3 > 0)
, im pretty sure that all of these numbers have to be greater than zero, right?
||
is "or"
and same thing for if (number1 < 31 || number2 < 12)
Yes || is or
Same thing with if
Sorry. I didn’t reply sooner I went to bed asa I posted it