Hello All,
why is this code is not showing the result in this format: 0.00 and
showing it as only 0
Private Sub btn1_Click
Debug.Print(For mat$(Rnd() * 100, "0.00"))
Dim d As Double = Math.Round(2250 .0, 3)
txt2.Text = txt1.Text \ d 8 3279
well, i thought that the Debug.print line apply to what is under it. and yes,
i'm talking about txt2. it always show 0, but i'm trying to get it to show
0.1
"Patrice" wrote:
Are you talking about what is shown in txt2 (is the Debug.print line
relevant ?)
What is the part of the code that makes you think it should behave this way
? (Math.Round ???)
--
Patrice
"karim" <ka***@discussi ons.microsoft.c oma crit dans le message de groupe
de discussion : 13************* *************** **...icrosof t.com...
Hello All,
why is this code is not showing the result in this format: 0.00 and
showing it as only 0
Private Sub btn1_Click
Debug.Print(For mat$(Rnd() * 100, "0.00"))
Dim d As Double = Math.Round(2250 .0, 3)
txt2.Text = txt1.Text \ d
"karim" <ka***@discussi ons.microsoft.c omschrieb
Hello All,
why is this code is not showing the result in this format:
0.00 and showing it as only 0
Private Sub btn1_Click
Debug.Print(For mat$(Rnd() * 100, "0.00"))
Dim d As Double = Math.Round(2250 .0, 3)
txt2.Text = txt1.Text \ d
Please enable Option Strict first. You must become aware of the data types
you are dealing with. Otherwise you will get unexpected results forever.
Second, you must convert strings to numeric values. You can not calculate
with strings.
"\" is an Integer division operator, that means, you can not divide floating
point values with it. Use "/" for floating point divisions.
A Double object has a ToString method that can be used easily.
Why do you want to round 2250 to 3 decimal places? It already has 0
decimal places.
Armin
Hello Armin Zingler
thank you very much. I didn't have option strict on. and
i don't want to round to the 2250 to 3 decimal places, what i want is to
divide whatever in txt1 by 2250 and display it in txt2 and #.###
No the format$ *function* takes two input values and return a value. Then
you print this returned formatted value... Period.
See also Armin post that contains basically my second round of remarks but I
wanted first to clarify why you thought you should have seen that before
moving on more advanced topic.
You may want to read again a programming introduction tutorial before moving
on.
--
Patrice
"karim" <ka***@discussi ons.microsoft.c oma écrit dans le message de groupe
de discussion : 45************* *************** **...icrosof t.com...
well, i thought that the Debug.print line apply to what is under it. and
yes,
i'm talking about txt2. it always show 0, but i'm trying to get it to show
0.1
"Patrice" wrote:
>Are you talking about what is shown in txt2 (is the Debug.print line relevant ?)
What is the part of the code that makes you think it should behave this way ? (Math.Round ???)
-- Patrice
"karim" <ka***@discussi ons.microsoft.c oma crit dans le message de groupe de discussion : 13************* *************** **...icrosof t.com...
Hello All,
why is this code is not showing the result in this format: 0.00
and
showing it as only 0
Private Sub btn1_Click
Debug.Print(For mat$(Rnd() * 100, "0.00"))
Dim d As Double = Math.Round(2250 .0, 3)
txt2.Text = txt1.Text \ d
well, I tried this:
txt2.Text = CStr(CDbl(txt1. Text) / 2250)
but it's showing lots of decimals. how can i get it to show only 2 or 3
decimals?
and thanks partice for leting me see that i didn't need the Debug.print or
the Math.Round.
the code works, i just needed the decimals. and now that i have the
decimals, they are too much...
karim wrote:
well, I tried this:
txt2.Text = CStr(CDbl(txt1. Text) / 2250)
but it's showing lots of decimals. how can i get it to show only 2 or
3 decimals?
and thanks partice for leting me see that i didn't need the
Debug.print or the Math.Round.
the code works, i just needed the decimals. and now that i have the
decimals, they are too much...
As Armin wrote, you can use .ToString:
txt2.Text = ((CDbl(txt1.Tex t) / 2250)).ToString ("0.000")
You can find out about the different things .ToString can do by googling for
vb.net tostring format
HTH
Andrew
This should give you two places to the right of the decimal
Dim Result As Double = CDbl(txt1.Text) / 2250
txt2.Text = Result.ToString ("##0.00;(##0.0 0);Zero")
"karim" <ka***@discussi ons.microsoft.c omwrote in message
news:EE******** *************** ***********@mic rosoft.com...
well, I tried this:
txt2.Text = CStr(CDbl(txt1. Text) / 2250)
but it's showing lots of decimals. how can i get it to show only 2 or 3
decimals?
and thanks partice for leting me see that i didn't need the Debug.print
or
the Math.Round.
the code works, i just needed the decimals. and now that i have the
decimals, they are too much...
"karim" <ka***@discussi ons.microsoft.c omschrieb
well, I tried this:
txt2.Text = CStr(CDbl(txt1. Text) / 2250)
but it's showing lots of decimals. how can i get it to show only 2
or 3 decimals?
and thanks partice for leting me see that i didn't need the
Debug.print or the Math.Round.
the code works, i just needed the decimals. and now that i have the
decimals, they are too much...
txt2.Text = (CDbl(txt1.Text ) / 2250).ToString( "0.000")
See also: http://msdn.microsoft.com/en-us/library/7wchwf6k.aspx
In addition, I suggest to add some checks because the text in txt1.text
might not be convertable to a Double. CDbl will fail then. For example:
Dim d As Double
If Double.TryParse (txt1.Text, d) Then
d = d / 2250
txt2.Text = d.ToString("0.0 00")
Else
MsgBox("invalid input", MsgBoxStyle.Inf ormation)
End If
Armin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Oswald |
last post by:
Hey,
how can I set the number of decimals?
Example:
5 decimals 2.12345
2 decimals 2.12
I've found something about NumberFormat in the API, but without an example I
can't solve this...
|
by: thx |
last post by:
I have MySQL 4.0.18 on Windows 2000 and I have a problem with floats
and decimals. The table has floats and decimals fields but when I
enter non-integers in these fields, they get rounded. So if I put
(either via PHP or the console or MySQL Control Center) 155.82 in a
float field, it is stored as 156. WHY IS THIS HAPPENING??
thanks
|
by: westjon64 |
last post by:
i am fairly new to c++, i need to know how to make it so you can input
decimals into a file using the cin >> a command instead of just being
able to input whole numbers and also how to make it so that it outputs
decimals and not just rounded off whole numbers
|
by: Donal McWeeney |
last post by:
Hi,
Is there a way to specify on the predefined format strings like P and N that
you want displayed all the decimals in the number...
for example
3 will display 3
2.1 will display 2.1
3.21 will display 3.21
|
by: vsts2007 |
last post by:
hi,
how can I change the number of decimals appeared in access reports... I put a formula in query and its giving three to four decimals in the output of report. I want to change the number of decimals to zero. can anybody guide me in this .
| |
by: CNiall |
last post by:
I am very new to Python (I started learning it just yesterday), but I
have encountered a problem.
I want to make a simple script that calculates the n-th root of a given
number (e.g. 4th root of 625--obviously five, but it's just an example
:P), and because there is no nth-root function in Python I will do this
with something like x**(1/n).
However, with some, but not all, decimals, they do not seem to 'equal
themselves'. This is...
|
by: Edwin.Madari |
last post by:
for nth square root: use math.sqrt n times for example
... num = math.sqrt(num)
...
5.0
all comparisons work fine for arbitrary floating point numbers...
For readability print them with required precision. for example
True
(0.20000000000000001, 0.20000000000000001)
('0.20', '0.20')
|
by: Tommy Nordgren |
last post by:
On 3 aug 2008, at 17.16, Edwin.Madari@VerizonWireless.com wrote:
Ehum. The OP wants to compute the nth root ( not the nth square root)
------
What is a woman that you forsake her, and the hearth fire and the home
acre,
to go with the old grey Widow Maker. --Kipling, harp song of the Dane
women
|
by: ssecorp |
last post by:
char* reverse(char* str) {
int length = strlen(str);
char* acc;
int i;
for (i=0; i<=length-1; i++){
acc = str;
}
return acc;
}
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |