I need to do some calculations in VB and display the results of the calculation as a decimal number like 1.62. In my code several variables have the Dim Double and some have the Dim Currency. The result of the calculation is always shown as a scientific number with a exponent e-2 or something like that. How can I change the format of the number in the textbox into a number with just two decimals?

Thanks a lot

I've got this idea, hope it works:
Assume SCI_Num is your scientific number, and Result is your final result.

SCI_Num = SCI_Num * 100
Result = Fix(SCI_Num)
Result = Result / 100

don't forget to tell me the results ;)

Hi Fix returns only integral part

Use Round (Number, NumberOfDigitAfterDecimal) to round off the value

Ex

Dim SCI_Num As Double
   
   SCI_Num = 22 / 7
   MsgBox SCI_Num
   MsgBox Round(SCI_Num, 2)

you need to use DECIMAL in place of DOUBLE for the variable data type.

The easiest way is to use the Format function.

Format(expression[, format[, firstdayofweek[, firstweekofyear]]])

Use something like:

Result = Format(VariableName, "##########.00")

Hi Fix returns only integral part

Well, that's right. But did you notice what my code was?

Let's say you have 126.85416 and you apply the code for it:

SCI_Num = SCI_Num * 100
'SCI_Num will be 12685.416

Result = Fix(SCI_Num)
'Result will be 12685

Result = Result / 100
'Result will be 126.85

And I believe this is exactly what we need to do ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.