0

I have 18.9954545454545454545454545 value and i need to convert it to currency format without rounding it.

18.9954545454545454545454545.ToString("c");

But returns me "$19.00" but i need "$18.99".

Is there any method to calculate this.

I have a method that gives me exactly what i need but don't think that method is good to implement.

@Convert.ToDecimal(18.9954545454545454545454545.Substring(0, 5)).ToString("c")

Thanks

Prince Chopra
  • 167
  • 11
  • 1
    Do you simply want to erase everything after the first 2 decimals, so 18.99999999 would become 18.99? – Simon Oct 22 '14 at 09:55
  • Do you think we can round off the total if we are working on some eCommerce project. Is it a good practice? @Simon – Prince Chopra Oct 22 '14 at 09:57
  • Or its fine to go with substring? @Simon – Prince Chopra Oct 22 '14 at 09:58
  • I am no expert in the financial world. I would personally ask my boss or someone higher up what to do with this. Do you want to round everything? What do we do with 18.995? It might be only 1 cent, but if that transaction is made a million times, it starts to make a difference. – Simon Oct 22 '14 at 09:59
  • Yes, That's what i am concerning about. – Prince Chopra Oct 22 '14 at 10:01
  • Maybe I'm stating the obvious, but `ToString()` doesn't actually do any rounding in the value; it just gives the closest approximation as a String. – Rik Oct 22 '14 at 10:02
  • You could put `F` after `18.9954545454545454545454545F`, maybe this would work. – bitcell Oct 22 '14 at 10:06
  • 1
    @UniCell that would just turn the `double` literal into a (single) `float`. You should always be using `decimal` when dealing with currency. You could turn the literal into a `decimal` by appending an `m`, but that doesn't solve this issue. – Rik Oct 22 '14 at 10:10

0 Answers0