decimal formatting without rounding .net

后端 未结 3 1130
悲&欢浪女
悲&欢浪女 2021-01-25 07:06

Yesterday I asked this general question about decimals and their internal precisions. Here is a specific question about the scenario I\'m trying to address.

I have colu

3条回答
  •  被撕碎了的回忆
    2021-01-25 07:54

    Anything you could do on the decimal itself wouldn't be enough for at least the following reason: you couldn't store in a decimal number itself that you want x leading/trailing zeroes to be printed as the value is converted to a string. The decimal data type in .NET is just a value type made up of 128bit, all dedicated to representing the number. No information about formatting when the number is printed is included, and the fact that it's a value type allows it to be quickly passed as an argument on the stack, which is also a relief for the GC.
    You could wrap decimal into some class, generate instances of that class in your DAL and return a collection of those if you need to do some number crunching later in the app and if that's not the case you could simply apply the "stringification" in your DAL and return a collection of strings.

提交回复
热议问题