-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
604 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
#nullable enable | ||
namespace Hohoema.Helpers; | ||
|
||
public static class NumberToKMGTPEZYStringHelper | ||
{ | ||
const string KMGTPEZY = "KMGTPEZY"; | ||
|
||
public static string ToKMGTPEZY(double number) | ||
{ | ||
int divCount = -1; | ||
while (number >= 1000.0d) | ||
{ | ||
number /= 1000.0d; | ||
divCount++; | ||
} | ||
|
||
if (divCount >= KMGTPEZY.Length) | ||
{ | ||
throw new NotSupportedException("ヨタより大きい桁数は対応してない"); | ||
} | ||
else if (divCount >= 2 /* G 以上なら */) | ||
{ | ||
return number.ToString("F2") + KMGTPEZY[divCount]; | ||
} | ||
else if (divCount >= 0 /* K 以上なら */) | ||
{ | ||
return number.ToString("F0") + KMGTPEZY[divCount]; | ||
} | ||
else | ||
{ | ||
return number.ToString("F0"); | ||
} | ||
} | ||
|
||
public static string ToKMGTPEZY(int number) | ||
{ | ||
int divCount = -1; | ||
while (number >= 1000) | ||
{ | ||
number /= 1000; | ||
divCount++; | ||
} | ||
|
||
if (divCount >= KMGTPEZY.Length) | ||
{ | ||
throw new NotSupportedException("ヨタより大きい桁数は対応してない"); | ||
} | ||
else if (divCount >= 2 /* G 以上なら */) | ||
{ | ||
return number.ToString("F2") + KMGTPEZY[divCount]; | ||
} | ||
else if (divCount >= 0 /* K 以上なら */) | ||
{ | ||
return number.ToString("F0") + KMGTPEZY[divCount]; | ||
} | ||
else | ||
{ | ||
return number.ToString("F0"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.