Fix Utility.FormatCurrency
This commit is contained in:
@@ -290,19 +290,32 @@ namespace MarketData.Utils
|
||||
}
|
||||
public static String FormatCurrency(double number)
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
if (double.NaN.Equals(number))sb.Append("N/A");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (double.NaN.Equals(number)) sb.Append("N/A");
|
||||
else sb.Append(String.Format("{0:C}", number));
|
||||
return sb.ToString();
|
||||
return Reformat(sb.ToString(), number) ;
|
||||
}
|
||||
|
||||
public static String FormatCurrency(double number,int decimals)
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
String currencyFormat="{0:C"+decimals+"}";
|
||||
if (double.NaN.Equals(number))sb.Append("N/A");
|
||||
else sb.Append(String.Format(currencyFormat, number));
|
||||
return sb.ToString();
|
||||
return Reformat(sb.ToString(), number);
|
||||
}
|
||||
|
||||
// This is a workaround for ARM64 architecture where the leading and trailing parens are omitted for negative numbers
|
||||
private static String Reformat(String str, double number)
|
||||
{
|
||||
if (String.IsNullOrEmpty(str)) return str;
|
||||
if (number < 0.00 && !str.StartsWith("("))
|
||||
{
|
||||
return "(" + str + ")";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String FormatPercent(double number)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user