Skip to content

Instantly share code, notes, and snippets.

@koolii
Created December 17, 2015 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koolii/2b10b7e27caa99669678 to your computer and use it in GitHub Desktop.
Save koolii/2b10b7e27caa99669678 to your computer and use it in GitHub Desktop.
var formatter = function(csv) {
var lines = csv.split("\n");
var result = [];
for (var i=0; i<lines.length;i++) {
var array = str.split(",");
var lineResult = [];
for (var i=0; i<array.length; i++) {
var strVal = array[i];
// 小数点第二位まで表示されていたら
if (strVal.indexOf("%") != -1) {
// 小数点第一位にまで丸める
strVal = parseFloat(strVal.slice(0, strVal.length - 1)).toFixed(1);
strVal = strVal + "%";
}
lineResult.push(strVal);
}
result.push(lineResult.join(","));
}
return result.join("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment