Skip to content

Commit 9248b30

Browse files
authored
Merge pull request #261 from AtlasOfLivingAustralia/254-string-format-locale
#254 set locale for String.format of decimal numbers
2 parents bcd3083 + e88b886 commit 9248b30

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

grails-app/services/au/org/ala/spatial/GridCutterService.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ class GridCutterService {
525525
res = res * 2
526526
}
527527
if (res != Double.parseDouble(resolution)) {
528-
resolution = String.format("%f", res)
528+
resolution = String.format(Locale.US, "%f", res)
529529
}
530530

531531
//get mask and adjust extents for filter

grails-app/services/au/org/ala/spatial/TabulationService.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class TabulationService {
7979
String value = null
8080
if (func == "area") {
8181
//sq km
82-
value = String.format("%.1f", t.getArea())
82+
value = String.format(Locale.US, "%.1f", t.getArea())
8383
} else if (func == "occurrences") {
8484
value = String.valueOf(t.getOccurrences())
8585
} else if (func == "species") {

src/main/groovy/au/org/ala/spatial/Util.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ class Util {
254254
String[] lines = new String[ja.size() + 1]
255255
lines[0] = "SPCODE,SCIENTIFIC_NAME,AUTHORITY_FULL,COMMON_NAME,FAMILY,GENUS_NAME,SPECIFIC_NAME,MIN_DEPTH,MAX_DEPTH,METADATA_URL,LSID,AREA_NAME,AREA_SQ_KM"
256256
ja.eachWithIndex {Distributions it, int idx ->
257-
String intersectArea = String.format("%.2f", Math.round(it.intersectArea ?: 0) as Double / 1000000.0)
257+
String intersectArea = String.format(Locale.US, "%.2f", Math.round(it.intersectArea ?: 0) as Double / 1000000.0)
258258

259259
lines[idx + 1] = it.spcode + "," + wrap(it.scientific) + "," + wrap(it.authority_) + "," + wrap(it.common_nam) + "," +
260260
wrap(it.family) + "," + wrap(it.genus_name) + "," + wrap(it.specific_n) + "," + (it.min_depth ?: "") + "," + (it.max_depth ?: "") +
261-
"," + wrap(it.metadata_u) + "," + wrap(it.lsid) + "," + wrap(it.area_name) + "," + String.format("%.2f", (it.area_km ?: 0) as Double) +
261+
"," + wrap(it.metadata_u) + "," + wrap(it.lsid) + "," + wrap(it.area_name) + "," + String.format(Locale.US, "%.2f", (it.area_km ?: 0) as Double) +
262262
"," + wrap(it.data_resource_uid) + "," + intersectArea
263263
}
264264

@@ -278,7 +278,7 @@ class Util {
278278
String key = wrap(it.family) + "," + wrap(it.scientific) + "," + wrap(it.common_nam) + "," + wrap(it.lsid)
279279

280280
String areaName = it.area_name
281-
String intersectArea = String.format("%.2f", Math.round(it.intersectArea ?: 0) as Double / 1000000)
281+
String intersectArea = String.format(Locale.US, "%.2f", Math.round(it.intersectArea ?: 0) as Double / 1000000)
282282

283283
if (areaName.toLowerCase().contains("likely")) likely.put(key, intersectArea)
284284
if (areaName.toLowerCase().contains("maybe")) maybe.put(key, intersectArea)

src/main/groovy/au/org/ala/spatial/intersect/Grid.groovy

+4-4
Original file line numberDiff line numberDiff line change
@@ -1087,10 +1087,10 @@ class Grid { // implements Serializable
10871087
fw.append("\r\n").append("Mapunits=DEGREES")
10881088
fw.append("\r\n").append("Columns=").append(String.valueOf(ncols))
10891089
fw.append("\r\n").append("Rows=").append(String.valueOf(nrows))
1090-
fw.append("\r\n").append("MinX=").append(String.format("%.2f", xmin))
1091-
fw.append("\r\n").append("MaxX=").append(String.format("%.2f", xmax))
1092-
fw.append("\r\n").append("MinY=").append(String.format("%.2f", ymin))
1093-
fw.append("\r\n").append("MaxY=").append(String.format("%.2f", ymax))
1090+
fw.append("\r\n").append("MinX=").append(String.format(Locale.US, "%.2f", xmin))
1091+
fw.append("\r\n").append("MaxX=").append(String.format(Locale.US, "%.2f", xmax))
1092+
fw.append("\r\n").append("MinY=").append(String.format(Locale.US, "%.2f", ymin))
1093+
fw.append("\r\n").append("MaxY=").append(String.format(Locale.US, "%.2f", ymax))
10941094
fw.append("\r\n").append("ResolutionX=").append(String.valueOf(xres))
10951095
fw.append("\r\n").append("ResolutionY=").append(String.valueOf(yres))
10961096
fw.append("\r\n").append("[Data]")

src/main/groovy/au/org/ala/spatial/process/AooEoo.groovy

+6-6
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ class AooEoo extends SlaveProcess {
153153
'<table >' +
154154
'<tr><td>Number of records used for the calculations</td><td>' + occurrenceCount + "</td></tr>" +
155155
'<tr><td>Species</td><td>' + species.name + '</td></tr>' +
156-
"<tr><td>Area of Occupancy (AOO: ${gridSize} degree grid)</td><td>" + String.format('%.0f', aoo) + ' sq km</td></tr>' +
157-
'<tr><td>Area of Occupancy (Points with radius: ' + String.format("%.0f", radius) + 'm)</td><td>' + String.format('%.0f', circleArea) + ' sq km</td></tr>' +
158-
'<tr><td>Extent of Occurrence (EOO: Minimum convex hull)</td><td>' + (String.format('%.0f', eoo)) + ' sq km</td></tr>' +
159-
((alphaHull != null) ? "<tr><td>Alpha Hull (Alpha: ${alpha})</td><td>" + String.format('%.0f', alphaHull) + ' sq km</td></tr>' : "") +
156+
"<tr><td>Area of Occupancy (AOO: ${gridSize} degree grid)</td><td>" + String.format(Locale.US, '%.0f', aoo) + ' sq km</td></tr>' +
157+
'<tr><td>Area of Occupancy (Points with radius: ' + String.format(Locale.US, "%.0f", radius) + 'm)</td><td>' + String.format(Locale.US, '%.0f', circleArea) + ' sq km</td></tr>' +
158+
'<tr><td>Extent of Occurrence (EOO: Minimum convex hull)</td><td>' + (String.format(Locale.US, '%.0f', eoo)) + ' sq km</td></tr>' +
159+
((alphaHull != null) ? "<tr><td>Alpha Hull (Alpha: ${alpha})</td><td>" + String.format(Locale.US, '%.0f', alphaHull) + ' sq km</td></tr>' : "") +
160160
'</table></body></html>' +
161161
'</div>'
162162

@@ -216,7 +216,7 @@ class AooEoo extends SlaveProcess {
216216
try {
217217
//point=latitude,longitude
218218
String[] ll = point.replace('\"', '').split(',')
219-
String s = String.format('POINT(%.6f %.6f)', Double.parseDouble(ll[1]), Double.parseDouble(ll[0]))
219+
String s = String.format(Locale.US, 'POINT(%.6f %.6f)', Double.parseDouble(ll[1]), Double.parseDouble(ll[0]))
220220
if (pointCount > 0) {
221221
sb.append(',')
222222
}
@@ -277,7 +277,7 @@ class AooEoo extends SlaveProcess {
277277
float x = (float) point.x
278278
float y = (float) point.y
279279

280-
String s = String.format('((%.6f %.6f,%.6f %.6f,%.6f %.6f,%.6f %.6f,%.6f %.6f))',
280+
String s = String.format(Locale.US, '((%.6f %.6f,%.6f %.6f,%.6f %.6f,%.6f %.6f,%.6f %.6f))',
281281
x, y,
282282
x, y + gridsize,
283283
x + gridsize, y + gridsize,

src/main/groovy/au/org/ala/spatial/util/AreaReportPDF.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,9 @@ class AreaReportPDF {
745745

746746
sb.append(StringEscapeUtils.escapeCsv(it.name1))
747747
sb.append(",")
748-
sb.append(String.format("%.2f", it.area / 1000000.0))
748+
sb.append(String.format(Locale.US, "%.2f", it.area / 1000000.0))
749749
sb.append(",")
750-
sb.append(String.format("%.2f", it.area / 1000000.0 / totalArea * 100))
750+
sb.append(String.format(Locale.US, "%.2f", it.area / 1000000.0 / totalArea * 100))
751751
row++
752752
}
753753
}

0 commit comments

Comments
 (0)