decimal
decimal copied to clipboard
Holp decimal format calculating expression
I hope decimal.Decimal
can have a method that show calculating expression, example:num1.Div(num2).Add(num3).Round(4)
. if num1=1.23, num2=2.34, num3=3.45, then it can format like as follow:
round(1.23 / 2.34 + 3.45, 4)
the real scene comes from the following code:
// ask * askSize/(askSize + bidSize) + bid * bidSize/(bidSize + askSize) // round(precision)
last := vv.Ask.Mul(vv.AskSize.Div(vv.AskSize.Add(vv.BidSize))).Add(vv.Bid.Mul(vv.BidSize.Div(vv.AskSize.Add(vv.BidSize)))).Round(precision)
now I have to comment it above.
Hi @Turing-Chu! That sounds like a great idea, but such a thing would require additional expression storage on the decimal
struct level, thus it will potentially increase the memory usage and I think most of the decimal lib users don't care about such feature.
Maybe there is a way to implement it without additional storage, but I need to think about that. Anyways, thanks for the idea!