Skip to content

Commit

Permalink
Merge pull request #740 from cggh/noFormatYear
Browse files Browse the repository at this point in the history
Don't format years toLocaleString
  • Loading branch information
benjeffery authored Nov 28, 2016
2 parents ec20985 + b900ff5 commit a54565b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions webapp/src/js/panoptes/Formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let JD2DateTime = function(JD) {
};

export default function(property, value) {

if (property.isText) {
return value === null ? '' : value;
}
Expand Down Expand Up @@ -32,9 +33,18 @@ export default function(property, value) {

// Try to convert string representations to float, e.g. "1.01" => 1.01
// Strings do not have a toFixed() method.
let parsedValue = parseFloat(value);
// Then fix to property.decimDigits.
// Then convert to LocaleString.
return parseFloat(value).toFixed(property.decimDigits).toLocaleString();

// NB: assuming isFloat never represent years, e.g. 2016
}

return parsedValue.toFixed(property.decimDigits).toLocaleString();
// Convert to LocaleString if numeric and not a year, e.g. 2016
if (!isNaN(value) && value > 999 && value <= 9999) {
// Preserve years, e.g. 2016
return value;
}

return value.toLocaleString();
}

0 comments on commit a54565b

Please sign in to comment.