473,473 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Formatting Text as Double with 2 Decimals

171 New Member
Hi,
I have got a field with numbers in it, which access automatically reads as text (it is a linked CSV text file). One example of a record in this field is -9.99999999999801E-03, when I do
Expand|Select|Wrap|Line Numbers
  1.  Format((Cdbl("-9.99999999999801E-03")),"#.##")
I get the answer as -.01, which should actually be -9.99.


Also if I had a number such as 3 if I did the same format command on it, i see '3.' instead of '3.00' can this be fixed? Maybe it doesn't even matter.


Thanks
Mar 3 '09 #1
8 20121
FishVal
2,653 Recognized Expert Specialist
@iheartvba
I don't see what is wrong here.

Also if I had a number such as 3 if I did the same format command on it, i see '3.' instead of '3.00' can this be fixed? Maybe it doesn't even matter.
Thanks
Use "0" instead of "#" in format string where you want to force zeroes.
To read comprehensive help about it open any table in design view, go to format property of any field and hit F1.
Mar 3 '09 #2
iheartvba
171 New Member
Hi Fishval,
Thanks for the quick response.

Expand|Select|Wrap|Line Numbers
  1.  Format((Cdbl("-9.99999999999801E-03")),"#.##")
Should this not return -9.99?

or does the E-03 move it 3 decimal places to the left?

I don't know why it's showing the E-03

Sorry If I'm confusing you. Sometimes the challenge is actually articulating the question, so thanks for your patience with me, as always
Mar 3 '09 #3
FishVal
2,653 Recognized Expert Specialist
Floating point .
Mar 3 '09 #4
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Sorry iheartVBA, Fish is rightly pointing out that it is you that is wrong in this case! The E notation tells us that the number is presented in a form of scientific notation, where numbers are represented by decimals to a particular power, as explained in detail in the Wikipedia link Fish provided.

In this case -9.99999...E-03 means -9.99999... * 10^(-3) = -0.0099999... which will round to -0.01 when displayed to two decimal places.

There is no problem at all here, at least not with Access or the CSV anyway...

-Stewart
Mar 3 '09 #5
NeoPa
32,556 Recognized Expert Moderator MVP
In case you were wondering, the second part of the question is also explained in the second part of post #2.
Mar 3 '09 #6
iheartvba
171 New Member
I suspected that about E being for exponent. It must be me doing some incorrect calculation. I couldn't see the Wikipedia link, that FishVal provided. Also with regards to my second question, I just tried it out and using 0 instead of # will give a 0 if there is no preexisting number there.

Many Thanks
Mar 3 '09 #7
NeoPa
32,556 Recognized Expert Moderator MVP
When formatting, # is generally just a place-holder.
#,##0.00 specifies that digits be grouped in blocks of three with a comma (,) separating. The zero (0) before the dot (.) indicates to display that digit even if zero.
Expand|Select|Wrap|Line Numbers
  1. 1234567.89 ==> 1,234,567.89
  2. .123456789 ==>         0.12
To show more digits (if available) after the decimal point, add hashes (#,##0.00########).
Expand|Select|Wrap|Line Numbers
  1. .123456789 ==>         0.123456789
Mar 4 '09 #8
iheartvba
171 New Member
Thanks guys. You have been a great help (as always)
Mar 4 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ike | last post by:
Does anyone know where I can find example scritp for formatting text input? I want to have a text box where only legitiamte filesname under unix can be netered (no whitespace, only alphanumeric,...
1
by: msmcg | last post by:
I need to format the data in some textboxes using the Binding method with custom Currency and ShortDate format and parse handlers. Here is the code that I am using. I call it on the form load...
2
by: CJ | last post by:
This is a really silly question, but I just can't get it right. I have a double; the value is 0.00003025. I want to display it exactly as it stands, but by default it is displayed in scientific...
0
by: gsb58 | last post by:
Hi! In my application I save text from a RichText box to file, but when previewing the text it turns out like: {\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Verdana;}}...
10
by: korund | last post by:
We can use special characters ('\n') to add line breaks in text in JavaScript popup Alert boxes. there is also few additional special characters: \' single quote \" double quote \&...
3
by: michael sorens | last post by:
The documentation for the RichTextBox is sketchy at best. I want to do a very simple task but I cannot find information on this. I am using a RichTextBox as an output window. Some text I want to...
6
by: Glen | last post by:
Hello again, I don't blame anyone for not answering my last post, since I obviously hadn't spent much time researching, but I've come a little ways and have another question. How can I better...
2
by: drfreaky | last post by:
Hello, I want to use a richtextbox for logging status messages. I have three kind of message types and want to use different formatting for them. My problem is, I change the color, add the text...
13
by: raylopez99 | last post by:
Refer to Int32.TryParse method: http://msdn.microsoft.com/en-us/library/zf50za27.aspx if you have to, specifically this example: numericString = "10345.72" styles = NumberStyles.Integer Or...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.