Razenpok / BreakInfinity.cs

Double replacement for numbers that go over 1e308
MIT License
212 stars 33 forks source link

How can I find a %? #3

Closed rasm685p closed 5 years ago

rasm685p commented 5 years ago

I'm trying to use a bigdouble number in a progress bar but it might not be possible? I wanted to do something like this:

BigDouble num1 = 1000;
BigDouble num2 = 100;

BigDouble num3 = (num2 / num1) * 100;

int num4 = Convert.ToInt32(num3);
hp1.Value = num4;
hp1.Maximum = 100;

Is this even possible? I tried converting it to a string and then back, but the number gets too large.

Patashu commented 5 years ago

try double num4 = num3.ToDouble(); or int num4 = (int)Math.Round(num3.ToDouble());

num4 should equal 10, representing 10% of a progress bar.

(Note that if you use VERY large numbers you may want to calculate progress bars in terms of the log10 of both numbers, like how Antimatter Dimensions does it.)

rasm685p commented 5 years ago

@Patashu Thank you! I can finally continue my "game" 👍

rasm685p commented 5 years ago

I'll close this. Thanks for making the BreakInfinity library

Razenpok commented 5 years ago

Yay! Sorted before I even wake up; cheers.

Side notes:

rasm685p commented 5 years ago

@Razenpok You might want to look at my github repository "Monster Hunt" if you got the time? But yeah I figured out that bigdouble isn't the best solution for everything 😃

Razenpok commented 5 years ago

Looks okay so far, though I'd suggest two things: