cmdolcet
asked on
Formating String values
My return value instead of looking like '1.00" it looks like "1"
How can I return it in the form "1.00"
CType(readingsOnScreen(int loop), Object).Text = tmpsaved.Value
How can I return it in the form "1.00"
CType(readingsOnScreen(int
string.Format("{0:N}",1)
or...
format(1,"0.00")
format(1,"0.00")
ASKER
If I add that code in the returned value is all "1.00" this is not waht I want What I need is for the numbers being return display past the "."
CType(readingsOnScreen(int loop), Object).Text = tmpsaved.Value.Format("{0: N}", 1)
CType(readingsOnScreen(int
Try this way
Dim value As Integer = 1
Debug.WriteLine(value.ToString("0.00"))
ASKER
I get the following error when i put in the code up top:
Error Target - ToSingle
Error Message - Conversion from string "L" to type 'Single' is not valid.
Exception Type - System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.Comp ilerServic es.Convers ions.Parse Double(Str ing Value, NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.Comp ilerServic es.Convers ions.ToSin gle(String Value, NumberFormatInfo NumberFormat)
Can anyone point me to the right direction
Error Target - ToSingle
Error Message - Conversion from string "L" to type 'Single' is not valid.
Exception Type - System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.Comp
at Microsoft.VisualBasic.Comp
Can anyone point me to the right direction
Public Class cSavedData
Public Characteristic As String
Public IsCalc As Boolean
Public Value As String
Public Index As Integer
Public Passed As Boolean
Public COMPort As String
Dim tmpsaved As cSavedData
CType(readingsOnScreen(intloop), Object).Text = tmpsaved.Value
tmpsaved.Value = ToString("0.00")
It should be
tmpsaved.Value = tmpsaved.Value.ToString("0 .00")
tmpsaved.Value = tmpsaved.Value.ToString("0
ASKER
I know get this error:
Error Information
Error Target - LoadSavedData
Error Message - Unable to cast object of type 'System.String' to type 'System.IFormatProvider'.
Exception Type - System.InvalidCastExceptio n: Unable to cast object of type 'System.String' to type 'System.IFormatProvider'.
at LMIObjectLibrary.NewRuntim eMethods.L oadSavedDa ta(ArrayLi st charsOnScreen, ArrayList& readingsOnScreen)
Stack Trace
Error Information
Error Target - LoadSavedData
Error Message - Unable to cast object of type 'System.String' to type 'System.IFormatProvider'.
Exception Type - System.InvalidCastExceptio
at LMIObjectLibrary.NewRuntim
Stack Trace
CType(readingsOnScreen(intloop), Object).Text = tmpsaved.Value
tmpsaved.Value = tmpsaved.Value.ToString("0.00")
But the error is not in the conversion!
Try to do this way to see if it works:
CType(readingsOnScreen(int loop), Object).Text = "1.00"
Try to do this way to see if it works:
CType(readingsOnScreen(int
ASKER
It shows all 1.00 on the screen
That's because the you're working with strings and not numbers
Try this way:
Try this way:
Dim str As String = "1"
Dim value As Integer
If Integer.TryParse(str, value) Then
Debug.WriteLine(value.ToString("0.00"))
End If
ASKER
Ok that code in your last response worked. It still gave me only 1.00
have do I get the actual value?
have do I get the actual value?
Try this:
Dim str As String = tmpsaved.Value
Dim value As Integer
If Integer.TryParse(str, value) Then
tmpsaved.Value = value.ToString("0.00")
End If
ASKER
It doesn;t go into the:
If Integer.TryParse(str, value) Then
tmpsaved.Value = value.ToString("0.00")
End If
loop??????
If Integer.TryParse(str, value) Then
tmpsaved.Value = value.ToString("0.00")
End If
loop??????
Can you show how you use it ?
ASKER
What do you mean I showed how I used it above?
What do you mean with "It doesn;t go into the" ? I don't understand that!
ASKER
The code below. it doesn;t go into the loop:
tmpsaved.Value = value.ToString("0.00")
it just steps over the condition completely
tmpsaved.Value = value.ToString("0.00")
it just steps over the condition completely
Dim str As String = tmpsaved.Value
Dim value As Integer
If Integer.TryParse(str, value) Then
tmpsaved.Value = value.ToString("0.00")
End If
That's because it's not a valid integer value.
What value are you using ?
What value are you using ?
ASKER
Im using the tmpsaved.Value which is a string value. however if i use the .tostring ("0.00") it will jsut return the 0.00 on my screen?
>> Im using the tmpsaved.Value which is a string value
Ok, but what value ... give an example.
Ok, but what value ... give an example.
ASKER
the value is 0.01 and sometimes the value is 0.3333333333 it just depends on what things read
but in any event i want it to display 0.01 or 0.33 I only want the 2 decimal palces
but in any event i want it to display 0.01 or 0.33 I only want the 2 decimal palces
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.