Merge pull request #38 from nventive/dev/dr/ConvertersOutput

Fix converters output / rouding
This commit is contained in:
David 2019-05-24 13:17:29 -04:00 committed by GitHub
commit 843d7d4111
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 12 deletions

View file

@ -618,8 +618,8 @@ namespace UnitConversionManager
CalculatorList<string> tokenList = StringToVector(w, ';');
Debug.Assert(tokenList.Size() == EXPECTEDSERIALIZEDCONVERSIONDATATOKENCOUNT);
ConversionData serializedConversionData = new ConversionData();
serializedConversionData.ratio = System.Convert.ToDouble(Unquote(tokenList[0]));
serializedConversionData.offset = System.Convert.ToDouble(Unquote(tokenList[1]));
serializedConversionData.ratio = System.Convert.ToDouble(Unquote(tokenList[0]), CultureInfo.InvariantCulture);
serializedConversionData.offset = System.Convert.ToDouble(Unquote(tokenList[1]), CultureInfo.InvariantCulture);
serializedConversionData.offsetFirst = (tokenList[2].CompareTo("1") == 0);
return serializedConversionData;
}
@ -1140,7 +1140,7 @@ namespace UnitConversionManager
{
if (cur.Key != m_fromType && cur.Key != m_toType)
{
double convertedValue = Convert(System.Convert.ToDouble(m_currentDisplay), cur.Value);
double convertedValue = Convert(System.Convert.ToDouble(m_currentDisplay, CultureInfo.InvariantCulture), cur.Value);
SuggestedValueIntermediate newEntry;
newEntry.magnitude = Math.Log10(convertedValue);
newEntry.value = convertedValue;
@ -1180,7 +1180,7 @@ namespace UnitConversionManager
{
roundedString = RoundSignificant(entry.value, 0);
}
if (System.Convert.ToDouble(roundedString) != 0.0 || m_currentCategory.supportsNegative)
if (System.Convert.ToDouble(roundedString, CultureInfo.InvariantCulture) != 0.0 || m_currentCategory.supportsNegative)
{
TrimString(ref roundedString);
returnVector.PushBack(Tuple.Create(roundedString, entry.type));
@ -1220,7 +1220,7 @@ namespace UnitConversionManager
}
// How to work out which is the best whimsical value to add to the vector?
if (System.Convert.ToDouble(roundedString) != 0.0)
if (System.Convert.ToDouble(roundedString, CultureInfo.InvariantCulture) != 0.0)
{
TrimString(ref roundedString);
whimsicalReturnVector.PushBack(Tuple.Create(roundedString, entry.type));
@ -1383,7 +1383,7 @@ namespace UnitConversionManager
}
Dictionary<Unit, ConversionData> conversionTable = m_ratioMap[m_fromType];
double returnValue = System.Convert.ToDouble(m_currentDisplay);
double returnValue = System.Convert.ToDouble(m_currentDisplay, CultureInfo.InvariantCulture);
if (conversionTable[m_toType].ratio == 1.0 && conversionTable[m_toType].offset == 0.0)
{
m_returnDisplay = m_currentDisplay;
@ -1407,11 +1407,11 @@ namespace UnitConversionManager
if (numPreDecimal > MAXIMUMDIGITSALLOWED || (returnValue != 0 && Math.Abs(returnValue) < MINIMUMDECIMALALLOWED))
{
m_returnDisplay = returnValue.ToString("e");
m_returnDisplay = returnValue.ToString("e", CultureInfo.InvariantCulture);
}
else
{
returnValue = System.Convert.ToDouble(m_returnDisplay);
returnValue = System.Convert.ToDouble(m_returnDisplay, CultureInfo.InvariantCulture);
string returnString;
if (m_currentDisplay.size() <= OPTIMALDIGITSALLOWED && Math.Abs(returnValue) >= OPTIMALDECIMALALLOWED)
{
@ -1451,7 +1451,7 @@ namespace UnitConversionManager
/// <param name="numSignificant">int number of significant digits to round to</param>
string RoundSignificant(double num, int numSignificant)
{
return num.ToString($"F{numSignificant}");
return num.ToString($"F{numSignificant}", CultureInfo.InvariantCulture);
}
void UpdateCurrencySymbols()

View file

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
@ -1089,9 +1090,9 @@ namespace CalculatorApp.ViewModel
if (IsCurrencyCurrentCategory)
{
// TODO UNO:
// string currencyResult = m_currencyFormatter.Format(System.Convert.ToDouble(stringToLocalize));
// string currencyResult = m_currencyFormatter.Format(System.Convert.ToDouble(stringToLocalize, CultureInfo.InvariantCulture));
// string currencyCode = m_currencyFormatter.Currency;
string currencyResult = System.Convert.ToDouble(stringToLocalize).ToString(CultureInfo.CurrentCulture);
string currencyResult = System.Convert.ToDouble(stringToLocalize, CultureInfo.InvariantCulture).ToString(CultureInfo.CurrentCulture);
string currencyCode = "TODO UNO";
// CurrencyFormatter always includes LangCode or Symbol. Make it include LangCode
@ -1112,7 +1113,7 @@ namespace CalculatorApp.ViewModel
// Then use the decimalFormatter to reformat the double to Platform String
// TODO UNO
//result = m_decimalFormatter.Format(System.Convert.ToDouble(stringToLocalize));
result = System.Convert.ToDouble(stringToLocalize).ToString(CultureInfo.CurrentCulture);
result = System.Convert.ToDouble(stringToLocalize, CultureInfo.InvariantCulture).ToString(CultureInfo.CurrentCulture);
}
if (hasDecimal)