forked from nkovacic/Sample-ASP.NET-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberHelper.cs
More file actions
51 lines (44 loc) · 1.27 KB
/
NumberHelper.cs
File metadata and controls
51 lines (44 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sample.Core.Utilities
{
public class NumberHelper
{
private static HashSet<Type> NumericTypes = new HashSet<Type>
{
typeof(decimal), typeof(byte), typeof(sbyte),
typeof(short), typeof(ushort), typeof(int), typeof(double)
};
public static double RoundDouble(double value, int numberOfDecimals = 0)
{
return Math.Round(value, numberOfDecimals);
}
public static decimal RoundDecimal(decimal value, int numberOfDecimals = 0)
{
return Math.Round(value, numberOfDecimals);
}
public static bool IsNumeric(string s)
{
float output;
return float.TryParse(s, out output);
}
public static bool IsNumeric(Type type)
{
return NumericTypes.Contains(type);
}
public static string FormatForMoney(decimal value)
{
if (value % 1 == 0)
{
return string.Format("{0:#.0}", value);
}
else
{
return string.Format("{0:#.0,##}", value);
}
}
}
}