FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MapWindow5/src/MW5.Shared/NumericHelper.cs at develop · MapWindow/MapWindow5 · GitHub
MapWindow
/
MapWindow5
Public
Notifications
You must be signed in to change notification settings
Fork
102
Star
308
Code
Issues
14
Pull requests
12
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
MapWindow5
/
src
/
MW5.Shared
/
NumericHelper.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
81 lines (70 loc) · 2.61 KB
Breadcrumbs
MapWindow5
/
src
/
MW5.Shared
/
NumericHelper.cs
Copy path
File metadata and controls
81 lines (70 loc) · 2.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using
System
;
using
System
.
Globalization
;
using
System
.
IO
;
namespace
MW5
.
Shared
{
/// <summary>
/// Class for performinc nummeric actions
/// </summary>
public
static
class
NumericHelper
{
private
const
double
Tolerance
=
1e-10
;
public
static
string
ToInvariantString
(
this
double
value
)
{
return
value
.
ToString
(
CultureInfo
.
InvariantCulture
)
;
}
public
static
bool
ParseDoubleInvariant
(
this
string
s
,
out
double
result
)
{
double
val
;
return
double
.
TryParse
(
s
,
NumberStyles
.
Any
,
CultureInfo
.
InvariantCulture
,
out
result
)
;
}
/// <summary>Check if a value is nummeric</summary>
/// <param name = "value">The value to check.</param>
/// <param name = "style">The NumberStyle</param>
/// <returns>Status indicating if value is nummeric</returns>
public
static
bool
IsNumeric
(
string
value
,
NumberStyles
style
)
{
double
result
;
return
double
.
TryParse
(
value
,
style
,
CultureInfo
.
CurrentCulture
,
out
result
)
;
}
/// <summary>
/// Returns true if to values are equal within tolerance.
/// </summary>
/// <param name="val1">The val1.</param>
/// <param name="val2">The val2.</param>
/// <returns></returns>
public
static
bool
Equal
(
double
val1
,
double
val2
)
{
return
Equal
(
val1
,
val2
,
Tolerance
)
;
}
/// <summary>
/// Returns true if to values are equal within tolerance.
/// </summary>
/// <param name="val1">The val1.</param>
/// <param name="val2">The val2.</param>
/// <param name="tolerance">Tolerance.</param>
/// <returns></returns>
public
static
bool
Equal
(
double
val1
,
double
val2
,
double
tolerance
)
{
return
Math
.
Abs
(
val2
-
val1
)
<=
tolerance
;
}
public
static
double
Parse
(
string
value
,
double
defaultValue
)
{
double
result
;
return
double
.
TryParse
(
value
,
out
result
)
?
result
:
defaultValue
;
}
public
static
string
FormatFileSize
(
double
size
)
{
string
[
]
sizes
=
{
"B"
,
"KB"
,
"MB"
,
"GB"
}
;
int
order
=
0
;
while
(
size
>=
1024
&&
order
+
1
<
sizes
.
Length
)
{
order
++
;
size
=
size
/
1024
;
}
// Adjust the format string to your preferences. For example "{0:0.#}{1}" would
// show a single decimal place, and no space.
return
String
.
Format
(
"{0:0.##} {1}"
,
size
,
sizes
[
order
]
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL