首页 \ 问答 \ StringBuilder和口音(StringBuilder and accent)

StringBuilder和口音(StringBuilder and accent)

我有一个StringBuilder ,我想写一个包含口音的文本到一个csv文件。

码:

StringBuilder strbr = new StringBuilder();
strbr.AppendLine("ù;é;à");
File.WriteAllText(filePath + ".csv", strbr.ToString());

但是当我打开我的csv文件时,只有: é

文件“test.csv”正确包含了ù;é;à ,但是当我用Excel打开它时,我有:

Excel截图

也许我错过了Excel的标题?


I have a StringBuilder and I want to write a text containing accent to an csv file.

Code:

StringBuilder strbr = new StringBuilder();
strbr.AppendLine("ù;é;à");
File.WriteAllText(filePath + ".csv", strbr.ToString());

But when I open my csv file, there is only: é

The file "test.csv' correctly contain ù;é;à, but when I open it with Excel I have:

Excel screenshot

Maybe I missed a header for Excel?


原文:https://stackoverflow.com/questions/49942162
更新时间:2023-04-26 07:04

最满意答案

function format_number($number) {
    $str = number_format($number, 4, '.', '');
    return preg_replace('/(?<=\d{2})0+$/', '', $str);
}

format_number(4.0)        // "4.00"
format_number(4.5)        // "4.50"
format_number(4.454)      // "4.454"
format_number(4.54545454) // "4.5455"
format_number(4.450)      // "4.45"

function format_number($number) {
    $str = number_format($number, 4, '.', '');
    return preg_replace('/(?<=\d{2})0+$/', '', $str);
}

format_number(4.0)        // "4.00"
format_number(4.5)        // "4.50"
format_number(4.454)      // "4.454"
format_number(4.54545454) // "4.5455"
format_number(4.450)      // "4.45"

相关问答

更多
  • $str = "1.23444"; print strlen(substr(strrchr($str, "."), 1)); $str = "1.23444"; print strlen(substr(strrchr($str, "."), 1));
  • 你可以使用number_format() : return number_format((float)$number, 2, '.', ''); 例: $foo = "105"; echo number_format((float)$foo, 2, '.', ''); // Outputs -> 105.00 此函数返回一个字符串 。 You can use number_format(): return number_format((float)$number, 2, '.', ''); Exam ...
  • 您可以使用正则表达式来解析value ,捕获小数位数并计算匹配的长度(如果有): import re def num_decimal_places(value): m = re.match(r"^[0-9]*\.([1-9]([0-9]*[1-9])?)0*$", value) return len(m.group(1)) if m is not None else 0 这比使用多个if else分割字符串要少一些“原始”,但不确定是否更简单或更易读。 You can use a reg ...
  • 每个人都在围绕浮点数在内部表示中没有小数位数的事实而跳舞。 即浮点数100 == 100.0 == 100.00 == 100.000,并且全部由相同的数字表示,有效地为100并且以这种方式存储。 当数字表示为字符串时,此示例中的小数位数只有一个上下文。 在这种情况下,可以使用任何计算小数点后数字的字符串函数来检查。 Everybody is dancing around the fact that floating point numbers don't have a number of decimal ...
  • function format_number($number) { $str = number_format($number, 4, '.', ''); return preg_replace('/(?<=\d{2})0+$/', '', $str); } format_number(4.0) // "4.00" format_number(4.5) // "4.50" format_number(4.454) // "4.454" format_nu ...
  • 对于舍入数字,你可以使用round() ,你也可以提到精度。 round($user['salary'], 2) 你可以在这里找到关于圆形函数的更多信息 希望这可以帮助。 For rounding numbers you can use the round() and you can mention the precision as well. round($user['salary'], 2) You can find more information on round function Here H ...
  • 您可以将0.0001添加到floatval($ startdate)并将0.0001添加到其他var以进行比较 floatval($startdate) + 0.0001 === $otherVar + 0.0001 You could add 0.0001 to floatval($startdate) and add 0.0001 to other var to compare them floatval($startdate) + 0.0001 === $otherVar + 0.0001
  • 乘以100: $grandTotal = $grandTotal * 100; // (moves decimal 2 places to right) 或删除期间: $grandTotal = str_replace('.','',$grandTotal); Either multiply by 100: $grandTotal = $grandTotal * 100; // (moves decimal 2 places to right) or remove the periods: $gran ...
  • 对于这个问题,Javascript会更容易。 尝试这个: