Hi guys,

i am a problem when i doing my coding about format a number

for normal number with 4 digit , i have idea which is
e.g: Dim a As double
a = 1/ 2946.33 ' its return is 0.00033940529

If i use format number function with 4digits, the answer is "0.0003"
but i need to the format number with 4 digit which is not included 0
: "0.0003394"

Can i anyone tell me how to do?

4
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by vb5prgrmr

e.g: Dim a As double
a = 1/ 2946.33 ' its return is 0.00033940529

If i use format number function with 4digits, the answer is "0.0003"
but i need to the format number with 4 digit which is not included 0
: "0.0003394"

This is really a job for Scientific Notation
As you point out Format(a,"0.0000") or Format(a,"0.####")
means that you lose digits you want to keep.

If you want, you can use:
Format(a,"0.########")
Then, you will always get 8 digits to the right of the decimal point.
But -- are your measurements really that precise and are they really that accurate? On part in a 100 million is very high accuracy/

A better way (in my opinion) would be: Format(a,"0.####E-##")
This would display as 3.3941E-4

--Vorpal

Or there is the formatnumber function...

``````?formatnumber(1/ 2946.33,8)
0.00033941``````

Where the "8" after the comma tells the function how many places after the decimal you want.

Good Luck