473,503 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

single to string problem

Hi,

can someone help me with that, it's driving me nuts...
-----
dim s as single = 42.5
dim msg as string = s.tostring()
' now msg is supposed to hold 42.5 but NO it's rather containing 43
-----
It seems the tostring() function rounds the number but I don't
understand why it does...

thanks,
ibiza

May 5 '06 #1
3 1234
ibiza,
Bizarre. I copy/pasted your code into a new console app (vb.net 2003)
and it worked fine. Have you tried overloading the ToString( ) with a
specific format string? Trying using s.tostring("r") and see if the
output is the same.

May 5 '06 #2
wow...with the "r" format string it seems to work ok
thank you so much!

Anyways, I wonder why this time the functions rounds the single...it
usually does NOT O_o
and what's the "r" for?
THANKS again! :)
ibiza

May 6 '06 #3
ibiza,

By default, ToString should return 7 digits of precision but it sounds
like it isn't doing that in your code. Passing it "r" or "R" in the
ToString method does this..."returns 7 digits if the number can be
represented with that precision or 9 digits if the number can only be
represented with maximum precision." - from the MSDN information on
Single.

May 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
5097
by: Dennis Plöger | last post by:
Hi all! I'm currently having some problems parsing a char array in c++. (And yes, I'm a half-newbie ;-)) Perhaps you can help me with this: #include <iostream> using std::cout; void...
6
8157
by: DLP22192 | last post by:
I have the following single-line if statement that is evaluating true even though it shouldn't. I have never seen this before and I am concerned that this can happen in other areas of my code. ...
2
4224
by: Diarmaid McGleenan | last post by:
Hi all. This isn't quite the same single/double-quote problem we see posted a multitude of times in this ng. Read on... I have a js function called ShowActiveLink which accepts a string...
5
11437
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
4
1644
by: Lampa Dario | last post by:
Hi, I need to estract single characters in a string, that may be '0' or '1', and evaluate them. I defined these variables char *binary; char cypher; int value;
4
1628
by: Paul | last post by:
I've got some code that adds a single quote to any ad hoc queries that appear to look like hacks. For instance, if somebody enters ' OR 1=1 -- then this code adds another single quote the string...
2
1166
by: Mika M | last post by:
Lets say I need to do something like this when running sql-sentences... Private Sub InsertIntoTable(ByVal ProductID As Integer, ByVal Amount As Single) Dim sql as String = String.Format("INSERT...
11
1850
by: Elmo | last post by:
Hi all! I am not very proud to ask this but here is my problem: string code = "\'13\'" The string code will have to contain following info: '51','52','63','other'... to get certain info...
3
1897
by: Richard S | last post by:
CODE: ASP.NET with C# DATABASE: ACCES alright, im having a problem, probably a small thing, but i cant figure out, nor find it in any other post, or on the internet realy (probably cuz i wouldnt...
23
13407
by: dkirkdrei | last post by:
I am having a bit of trouble trying to double up on slashes in a file path. What I am trying to do is very similar to the code below: <? $var =...
0
7203
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
7089
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...
1
6995
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...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4678
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...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
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 ...
1
738
muto222
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.