mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-23 06:25:19 -07:00
Fix converters output / rouding
This commit is contained in:
parent
fc5ad2da1e
commit
b246894845
2 changed files with 13 additions and 12 deletions
|
@ -618,8 +618,8 @@ namespace UnitConversionManager
|
||||||
CalculatorList<string> tokenList = StringToVector(w, ';');
|
CalculatorList<string> tokenList = StringToVector(w, ';');
|
||||||
Debug.Assert(tokenList.Size() == EXPECTEDSERIALIZEDCONVERSIONDATATOKENCOUNT);
|
Debug.Assert(tokenList.Size() == EXPECTEDSERIALIZEDCONVERSIONDATATOKENCOUNT);
|
||||||
ConversionData serializedConversionData = new ConversionData();
|
ConversionData serializedConversionData = new ConversionData();
|
||||||
serializedConversionData.ratio = System.Convert.ToDouble(Unquote(tokenList[0]));
|
serializedConversionData.ratio = System.Convert.ToDouble(Unquote(tokenList[0]), CultureInfo.InvariantCulture);
|
||||||
serializedConversionData.offset = System.Convert.ToDouble(Unquote(tokenList[1]));
|
serializedConversionData.offset = System.Convert.ToDouble(Unquote(tokenList[1]), CultureInfo.InvariantCulture);
|
||||||
serializedConversionData.offsetFirst = (tokenList[2].CompareTo("1") == 0);
|
serializedConversionData.offsetFirst = (tokenList[2].CompareTo("1") == 0);
|
||||||
return serializedConversionData;
|
return serializedConversionData;
|
||||||
}
|
}
|
||||||
|
@ -1140,7 +1140,7 @@ namespace UnitConversionManager
|
||||||
{
|
{
|
||||||
if (cur.Key != m_fromType && cur.Key != m_toType)
|
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;
|
SuggestedValueIntermediate newEntry;
|
||||||
newEntry.magnitude = Math.Log10(convertedValue);
|
newEntry.magnitude = Math.Log10(convertedValue);
|
||||||
newEntry.value = convertedValue;
|
newEntry.value = convertedValue;
|
||||||
|
@ -1180,7 +1180,7 @@ namespace UnitConversionManager
|
||||||
{
|
{
|
||||||
roundedString = RoundSignificant(entry.value, 0);
|
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);
|
TrimString(ref roundedString);
|
||||||
returnVector.PushBack(Tuple.Create(roundedString, entry.type));
|
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?
|
// 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);
|
TrimString(ref roundedString);
|
||||||
whimsicalReturnVector.PushBack(Tuple.Create(roundedString, entry.type));
|
whimsicalReturnVector.PushBack(Tuple.Create(roundedString, entry.type));
|
||||||
|
@ -1383,7 +1383,7 @@ namespace UnitConversionManager
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<Unit, ConversionData> conversionTable = m_ratioMap[m_fromType];
|
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)
|
if (conversionTable[m_toType].ratio == 1.0 && conversionTable[m_toType].offset == 0.0)
|
||||||
{
|
{
|
||||||
m_returnDisplay = m_currentDisplay;
|
m_returnDisplay = m_currentDisplay;
|
||||||
|
@ -1407,11 +1407,11 @@ namespace UnitConversionManager
|
||||||
|
|
||||||
if (numPreDecimal > MAXIMUMDIGITSALLOWED || (returnValue != 0 && Math.Abs(returnValue) < MINIMUMDECIMALALLOWED))
|
if (numPreDecimal > MAXIMUMDIGITSALLOWED || (returnValue != 0 && Math.Abs(returnValue) < MINIMUMDECIMALALLOWED))
|
||||||
{
|
{
|
||||||
m_returnDisplay = returnValue.ToString("e");
|
m_returnDisplay = returnValue.ToString("e", CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
returnValue = System.Convert.ToDouble(m_returnDisplay);
|
returnValue = System.Convert.ToDouble(m_returnDisplay, CultureInfo.InvariantCulture);
|
||||||
string returnString;
|
string returnString;
|
||||||
if (m_currentDisplay.size() <= OPTIMALDIGITSALLOWED && Math.Abs(returnValue) >= OPTIMALDECIMALALLOWED)
|
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>
|
/// <param name="numSignificant">int number of significant digits to round to</param>
|
||||||
string RoundSignificant(double num, int numSignificant)
|
string RoundSignificant(double num, int numSignificant)
|
||||||
{
|
{
|
||||||
return num.ToString($"F{numSignificant}");
|
return num.ToString($"F{numSignificant}", CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateCurrencySymbols()
|
void UpdateCurrencySymbols()
|
||||||
|
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
@ -1089,9 +1090,9 @@ namespace CalculatorApp.ViewModel
|
||||||
if (IsCurrencyCurrentCategory)
|
if (IsCurrencyCurrentCategory)
|
||||||
{
|
{
|
||||||
// TODO UNO:
|
// 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 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";
|
string currencyCode = "TODO UNO";
|
||||||
|
|
||||||
// CurrencyFormatter always includes LangCode or Symbol. Make it include LangCode
|
// 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
|
// Then use the decimalFormatter to reformat the double to Platform String
|
||||||
// TODO UNO
|
// TODO UNO
|
||||||
//result = m_decimalFormatter.Format(System.Convert.ToDouble(stringToLocalize));
|
//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)
|
if (hasDecimal)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue