Skip to content

Commit ca582af

Browse files
Add locale decimal condition example script
1 parent 1fac0f0 commit ca582af

1 file changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
Import-Module .\PSWriteHTML.psd1 -Force
2+
3+
$htmlDot = @(
4+
[PSCustomObject] @{
5+
Item = 'Pass threshold'
6+
Value = '0.17'
7+
}
8+
[PSCustomObject] @{
9+
Item = 'Fail threshold'
10+
Value = '0.25'
11+
}
12+
[PSCustomObject] @{
13+
Item = 'Exact threshold'
14+
Value = '0.20'
15+
}
16+
[PSCustomObject] @{
17+
Item = 'Negative value'
18+
Value = '-0.05'
19+
}
20+
)
21+
22+
$htmlComma = @(
23+
[PSCustomObject] @{
24+
Item = 'Pass threshold'
25+
Value = '0,17'
26+
}
27+
[PSCustomObject] @{
28+
Item = 'Fail threshold'
29+
Value = '0,25'
30+
}
31+
[PSCustomObject] @{
32+
Item = 'Exact threshold'
33+
Value = '0,20'
34+
}
35+
[PSCustomObject] @{
36+
Item = 'Negative value'
37+
Value = '-0,05'
38+
}
39+
)
40+
41+
$jsDot = @(
42+
[PSCustomObject] @{
43+
Item = 'Pass threshold'
44+
Value = 0.17
45+
}
46+
[PSCustomObject] @{
47+
Item = 'Fail threshold'
48+
Value = 0.25
49+
}
50+
[PSCustomObject] @{
51+
Item = 'Exact threshold'
52+
Value = 0.20
53+
}
54+
[PSCustomObject] @{
55+
Item = 'Negative value'
56+
Value = -0.05
57+
}
58+
)
59+
60+
$jsComma = @(
61+
[PSCustomObject] @{
62+
Item = 'Pass threshold'
63+
Value = '0,17'
64+
}
65+
[PSCustomObject] @{
66+
Item = 'Fail threshold'
67+
Value = '0,25'
68+
}
69+
[PSCustomObject] @{
70+
Item = 'Exact threshold'
71+
Value = '0,20'
72+
}
73+
[PSCustomObject] @{
74+
Item = 'Negative value'
75+
Value = '-0,05'
76+
}
77+
)
78+
79+
$exampleCode = @'
80+
New-TableCondition -Name "Value" -ComparisonType number -Operator le -Value 0.2 -Color SeaGreen -FailColor FireBrick
81+
New-TableCondition -Name "Value" -ComparisonType number -Operator le -Value '0,2' -Color SeaGreen -FailColor FireBrick
82+
83+
# Avoid bare -Value 0,2 in PowerShell.
84+
# PowerShell parses it as an Object[] containing 0 and 2.
85+
'@
86+
87+
New-HTML -TitleText 'PSWriteHTML decimal number conditions' -Online -FilePath "$PSScriptRoot\Example-LocaleDecimals.html" {
88+
New-HTMLSection -HeaderText 'Locale decimal conditions' {
89+
New-HTMLText -TextBlock {
90+
'This example proves the same decimal comparison works for HTML-backed tables and JavaScript-backed tables.'
91+
'Use -Value 0.2 for a numeric literal, or quote locale-formatted text with -Value ''0,2''.'
92+
'Do not use bare -Value 0,2 in PowerShell because it becomes an Object[] before PSWriteHTML sees it.'
93+
}
94+
New-HTMLCodeBlock -Code $exampleCode -Style 'PowerShell' -Theme enlighter
95+
}
96+
97+
New-HTMLSection -HeaderText 'HTML store with dot decimals' {
98+
New-HTMLTable -DataTable $htmlDot -Buttons copyHtml5, excelHtml5, csvHtml5, pdfHtml5 -PagingLength 5 {
99+
New-TableCondition -Name 'Value' -ComparisonType number -Operator le -Value 0.2 -Color SeaGreen -FailColor FireBrick
100+
}
101+
}
102+
103+
New-HTMLSection -HeaderText 'HTML store with comma decimals' {
104+
New-HTMLTable -DataTable $htmlComma -Buttons copyHtml5, excelHtml5, csvHtml5, pdfHtml5 -PagingLength 5 {
105+
New-TableCondition -Name 'Value' -ComparisonType number -Operator le -Value '0,2' -Color SeaGreen -FailColor FireBrick
106+
}
107+
}
108+
109+
New-HTMLSection -HeaderText 'JavaScript store with numeric values' {
110+
New-HTMLTable -DataTable $jsDot -Buttons copyHtml5, excelHtml5, csvHtml5, pdfHtml5 -PagingLength 5 {
111+
New-TableCondition -Name 'Value' -ComparisonType number -Operator le -Value 0.2 -Color SeaGreen -FailColor FireBrick
112+
} -DataStore JavaScript
113+
}
114+
115+
New-HTMLSection -HeaderText 'JavaScript store with comma-formatted strings' {
116+
New-HTMLTable -DataTable $jsComma -Buttons copyHtml5, excelHtml5, csvHtml5, pdfHtml5 -PagingLength 5 {
117+
New-TableCondition -Name 'Value' -ComparisonType number -Operator le -Value '0,2' -Color SeaGreen -FailColor FireBrick
118+
} -DataStore JavaScript
119+
}
120+
}

0 commit comments

Comments
 (0)