From fbd2beb34885210f061e0a5d3407b1ffd658be77 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 10 Oct 2016 02:52:03 +0200 Subject: [PATCH] Hopefuly fixed convert --- .../Searches/Commands/UnitConversion.cs | 18 +++++++++--------- src/NadekoBot/_Extensions/Extensions.cs | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Commands/UnitConversion.cs b/src/NadekoBot/Modules/Searches/Commands/UnitConversion.cs index 9b2da234..53c67413 100644 --- a/src/NadekoBot/Modules/Searches/Commands/UnitConversion.cs +++ b/src/NadekoBot/Modules/Searches/Commands/UnitConversion.cs @@ -109,7 +109,7 @@ namespace NadekoBot.Modules.Searches await msg.ReplyLong(sb.ToString(), breakOn: new[] { "```xl\n", "\n" }); } [NadekoCommand, Usage, Description, Aliases] - public async Task Convert(IUserMessage msg, string origin, string target, double value) + public async Task Convert(IUserMessage msg, string origin, string target, decimal value) { var originUnit = Units.Find(x => x.Triggers.Select(y => y.ToLowerInvariant()).Contains(origin.ToLowerInvariant())); var targetUnit = Units.Find(x => x.Triggers.Select(y => y.ToLowerInvariant()).Contains(target.ToLowerInvariant())); @@ -123,7 +123,7 @@ namespace NadekoBot.Modules.Searches await msg.Reply(string.Format("Cannot convert {0} to {1}: types of unit are not equal", originUnit.Triggers.First(), targetUnit.Triggers.First())); return; } - double res; + decimal res; if (originUnit.Triggers == targetUnit.Triggers) res = value; else if (originUnit.UnitType == "temperature") { @@ -131,10 +131,10 @@ namespace NadekoBot.Modules.Searches switch (originUnit.Triggers.First().ToUpperInvariant()) { case "C": - res = value + 273.15; //celcius! + res = value + 273.15m; //celcius! break; case "F": - res = (value + 459.67) * (5 / 9); + res = (value + 459.67m) * (5 / 9); break; default: res = value; @@ -144,10 +144,10 @@ namespace NadekoBot.Modules.Searches switch (targetUnit.Triggers.First()) { case "C": - res = value - 273.15; //celcius! + res = value - 273.15m; //celcius! break; case "F": - res = res * (9 / 5) - 458.67; + res = res * (9 / 5) - 458.67m; break; default: break; @@ -157,14 +157,14 @@ namespace NadekoBot.Modules.Searches { if (originUnit.UnitType == "currency") { - res = (value * (double)targetUnit.Modifier) / (double)originUnit.Modifier; + res = (value * targetUnit.Modifier) / originUnit.Modifier; } else - res = (value * (double)originUnit.Modifier) / (double)targetUnit.Modifier; + res = (value * originUnit.Modifier) / targetUnit.Modifier; } res = Math.Round(res, 2); - await msg.Reply(string.Format("{0} {1}s is equal to {2} {3}s", value, originUnit.Triggers.First().SnPl(value.IsInteger() ? (int)value : 2), res, targetUnit.Triggers.First().SnPl(res.IsInteger() ? (int)res : 2))); + await msg.Reply(string.Format("{0} {1} is equal to {2} {3}", value, (originUnit.Triggers.First() + "s").SnPl(value.IsInteger() ? (int)value : 2), res, (targetUnit.Triggers.First() + "s").SnPl(res.IsInteger() ? (int)res : 2))); } } diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 9089646a..d73eab9b 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -23,7 +23,7 @@ namespace NadekoBot.Extensions http.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); } - public static bool IsInteger(this double number) => number == Math.Truncate(number); + public static bool IsInteger(this decimal number) => number == Math.Truncate(number); public static string SanitizeMentions(this string str) => str.Replace("@everyone", "@everyοne").Replace("@here", "@һere");