Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String 3 decimal places

Example 1

Dim myStr As String = "38"

I want my result to be 38.000 ...


Example 2

myStr = "6.4"

I want my result to be 6.400


What is the best method to achieve this? I want to format a string variable with atleast three decimal places.

like image 421
Alex Avatar asked May 09 '13 15:05

Alex


People also ask

What does 3 decimal places mean?

What does Rounding Off to Three Decimal Places Mean? Rounding to Three Decimal Places is the process of rounding to thousandths place i.e. 3nd place to the right of decimal point. For Example 5.5380 rounded to three decimal places is 5.538.

What is a decimal string?

string decimal-string(number, number) The first number parameter is the number to be rounded. The second parameter gives the number of digits of precision past the decimal point to use.

How do you format a string to show two decimal places?

String strDouble = String. format("%. 2f", 1.23456); This will format the floating point number 1.23456 up-to 2 decimal places, because we have used two after decimal point in formatting instruction %.


1 Answers

Use FormatNumber:

Dim myStr As String = "38"
MsgBox(FormatNumber(CDbl(myStr), 3))

Dim myStr2 As String = "6.4"
MsgBox(FormatNumber(CDbl(myStr2), 3))
like image 87
GJKH Avatar answered Sep 22 '22 13:09

GJKH