Limiting double to 3 decimal places

前端 未结 8 2210
小鲜肉
小鲜肉 2020-11-27 04:38

This i what I am trying to achieve:

If a double has more than 3 decimal places, I want to truncate any decimal places beyond the third. (do not round.)



        
8条回答
  •  隐瞒了意图╮
    2020-11-27 05:07

    I can't think of a reason to explicitly lose precision outside of display purposes. In that case, simply use string formatting.

    double example = 12.34567;
    
    Console.Out.WriteLine(example.ToString("#.000"));
    

提交回复
热议问题