Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions main/SS/UserModel/DataFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -894,12 +894,15 @@ public override object ParseObject(string source, int pos)

private FormatBase CreateNumberFormat(string formatStr, double cellValue)
{
// Check for alternate grouping BEFORE cleaning (backslash stripping) so that
// escaped literal characters like \- are not misidentified as grouping chars.
// eg for a format like #'##0 which wants 12'345 not 12,345
Match agm = alternateGrouping.Match(formatStr);

string format = cleanFormatForNumber(formatStr);
NumberFormatInfo symbols = decimalSymbols;

// Do we need to change the grouping character?
// eg for a format like #'##0 which wants 12'345 not 12,345
Match agm = alternateGrouping.Match(format);
if (agm.Success)
{
char grouping = agm.Groups[2].Value[0];
Expand Down
6 changes: 3 additions & 3 deletions main/SS/Util/Format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private SSNFormat()
/** Format a number as an SSN */
public override string Format(object obj, CultureInfo culture)
{
var result = ((double)obj).ToString(df, culture);
var result = Convert.ToDouble(obj, CultureInfo.InvariantCulture).ToString(df, culture);
var sb = new StringBuilder();
sb.Append(result.Substring(0, 3)).Append('-');
sb.Append(result.Substring(3, 2)).Append('-');
Expand Down Expand Up @@ -99,7 +99,7 @@ private ZipPlusFourFormat()
/** Format a number as Zip + 4 */
public override string Format(object obj, CultureInfo culture)
{
var result = ((double)obj).ToString(df, culture);
var result = Convert.ToDouble(obj, CultureInfo.InvariantCulture).ToString(df, culture);
return result.Substring(0, 5)+'-'+result.Substring(5, 4);
}

Expand Down Expand Up @@ -137,7 +137,7 @@ private PhoneFormat()
/** Format a number as a phone number */
public override string Format(object obj, CultureInfo culture)
{
var result = ((double)obj).ToString(df, culture);
var result = Convert.ToDouble(obj, CultureInfo.InvariantCulture).ToString(df, culture);
var sb = new StringBuilder();
String seg1, seg2, seg3;
var len = result.Length;
Expand Down
13 changes: 13 additions & 0 deletions testcases/main/SS/UserModel/TestDataFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,19 @@ Excel displays the month instead of minutes."
* bug 60422 : DataFormatter has issues with a specific NumberFormat in Germany default locale
* Currently, this test only passes if you set LocaleUtil.setUserLocale(Locale.ROOT) or Locale.US.
*/
[Test]
public void TestPhoneNumberFormat()
{
DataFormatter formatter = new DataFormatter(CultureInfo.GetCultureInfo("en-US"));

// Bug: alternateGrouping regex should not misidentify escaped literal '-' as a grouping character
ClassicAssert.AreEqual("(123) 456-7890", formatter.FormatRawCellContents(1234567890, -1, "[<=9999999]###\\-####;\\(###\\)\\ ###\\-####"));
ClassicAssert.AreEqual("123-456-7890", formatter.FormatRawCellContents(1234567890, -1, "###\\-###\\-####"));

// Bug: SSNFormat/ZipPlusFourFormat/PhoneFormat must handle decimal values passed by FormatRawCellContents
ClassicAssert.AreEqual("(123) 456-7890", formatter.FormatRawCellContents(1234567890, -1, "[<=9999999]###-####;(###) ###-####"));
}

[Test]
public void TestBug60422()
{
Expand Down
Loading