0

Code:

Dim mp as Decimal

mp = 2056834 / 36 MsgBox(mp, vbInformation)

Output: 57134.2777777778

I was expecting the output to be:

Output: 57134.27777777778

What suppose to be the problem on why it was short of a decimal point?

skidl0ck
  • 15
  • 3
  • 1
    Use `mp = 2056834D / 36D`. You're currently using `Double` division. – 41686d6564 stands w. Palestine Nov 25 '22 at 02:27
  • 1
    You should enable [`Option Strict`](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/option-strict-statement) so that the compiler prevents you from doing those kinds of mistakes. See [What do Option Strict and Option Explicit do?](https://stackoverflow.com/q/2454552/8967612) and [Can I set Option Explicit and Option Strict on a Project/Solution level?](https://stackoverflow.com/q/5076851/8967612) – 41686d6564 stands w. Palestine Nov 25 '22 at 02:28
  • Does this answer your question? [Difference between decimal, float and double in .NET?](https://stackoverflow.com/questions/618535/difference-between-decimal-float-and-double-in-net) – 41686d6564 stands w. Palestine Nov 25 '22 at 02:29

1 Answers1

0

Try this:

Dim mp As Decimal

mp = Math.Round(CDec(2056834) / CDec(36), 11)
MsgBox(mp, vbInformation)

This will produce the expected output: 57134.27777777778

Jonathan Barraone
  • 489
  • 1
  • 3
  • 20