mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
[PTRun][Calc]Keep leading zeroes on languages where . is not a separator (#28451)
* [PTRun][Calc]Keep leading zeroes on languages where . is not a separator * Adapt tests
This commit is contained in:
@@ -76,10 +76,30 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
||||
string[] tokens = splitRegex.Split(input);
|
||||
foreach (string token in tokens)
|
||||
{
|
||||
int leadingZeroCount = 0;
|
||||
|
||||
// Count leading zero characters.
|
||||
foreach (char c in token)
|
||||
{
|
||||
if (c != '0')
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
leadingZeroCount++;
|
||||
}
|
||||
|
||||
// number is all zero characters. no need to add zero characters at the end.
|
||||
if (token.Length == leadingZeroCount)
|
||||
{
|
||||
leadingZeroCount = 0;
|
||||
}
|
||||
|
||||
decimal number;
|
||||
|
||||
outputBuilder.Append(
|
||||
decimal.TryParse(token, NumberStyles.Number, cultureFrom, out number)
|
||||
? number.ToString(cultureTo)
|
||||
? (new string('0', leadingZeroCount) + number.ToString(cultureTo))
|
||||
: token);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user