Get Last 2 Decimal Places with No Rounding

前端 未结 5 1990
青春惊慌失措
青春惊慌失措 2021-02-06 04:05

In C#, I\'m trying to get the last two decimal places of a double with NO rounding. I\'ve tried everything from Math.Floor to Math.Truncate and nothin

5条回答
  •  失恋的感觉
    2021-02-06 04:45

    Math.Round(NumberToRound - (double)0.005,2)
    

    i.e

    Math.Round(53.5821 - (double)0.005,2) // 53.58
    Math.Round(53.5899 - (double)0.005,2) // 53.58
    Math.Round(53.5800 - (double)0.005,2) // 53.58
    

提交回复
热议问题