How to format number?

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2007
Posts: 26
Reputation: nokomoli is an unknown quantity at this point 
Solved Threads: 0
nokomoli nokomoli is offline Offline
Light Poster

How to format number?

 
0
  #1
May 27th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 5
Reputation: Vorpal is an unknown quantity at this point 
Solved Threads: 0
Vorpal Vorpal is offline Offline
Newbie Poster

Re: How to format number?

 
0
  #2
May 27th, 2009
Originally Posted by nokomoli View Post
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 901
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 167
vb5prgrmr vb5prgrmr is offline Offline
Posting Shark

Re: How to format number?

 
0
  #3
May 27th, 2009
Or there is the formatnumber function...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ?formatnumber(1/ 2946.33,8)
  2. 0.00033941
Where the "8" after the comma tells the function how many places after the decimal you want.

Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 2
Reputation: Jouni79 is an unknown quantity at this point 
Solved Threads: 0
Jouni79 Jouni79 is offline Offline
Newbie Poster

Re: How to format number?

 
0
  #4
Jun 2nd, 2009
how about this sitsuation:

=FormatNumber(Sum(Fields!TotalProductPrice.Value),2)
it returns for exsample following: 1.2345. I need to replace . with ,
how can I do it
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 901
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 167
vb5prgrmr vb5prgrmr is offline Offline
Posting Shark

Re: How to format number?

 
0
  #5
Jun 2nd, 2009
The replace function.

However, let me remind you that you should have started your own thread and if you wanted to reference this thread you could have copied the url and posted it with your post with words like, in reference to...

Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC