If I try that exact code:
StringBuilder sb = new StringBuilder();
sb.Append("function myFunction(value, total) {");
sb.Append(" var percent = Number(100 * value / total).toFixed(1);");
sb.Append(" return percent;");
sb.Append("}");
string s = sb.ToString();
What I get is exactly what I expect:
function myFunction(value, total) { var percent = Number(100 * value / total).toFixed(1); return percent;}
So you are either not doing something I am, or doing something I'm not!
How does mine differ from yours?