Link to home
Start Free TrialLog in
Avatar of cmdolcet
cmdolcetFlag for United States of America

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(intloop), Object).Text = tmpsaved.Value
Avatar of rettiseert
rettiseert

string.Format("{0:N}",1)
or...

format(1,"0.00")
Avatar of cmdolcet

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(intloop), Object).Text = tmpsaved.Value.Format("{0:N}", 1)
Avatar of Jorge Paulino
Try this way
 
 

        Dim value As Integer = 1
        Debug.WriteLine(value.ToString("0.00"))

Open in new window

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.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
   at Microsoft.VisualBasic.CompilerServices.Conversions.ToSingle(String Value, NumberFormatInfo NumberFormat)

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")

Open in new window

It should be
tmpsaved.Value = tmpsaved.Value.ToString("0.00")

 
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.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.IFormatProvider'.
   at LMIObjectLibrary.NewRuntimeMethods.LoadSavedData(ArrayList charsOnScreen, ArrayList& readingsOnScreen)
Stack Trace
CType(readingsOnScreen(intloop), Object).Text = tmpsaved.Value
tmpsaved.Value = tmpsaved.Value.ToString("0.00")

Open in new window

But the error is not in the conversion!
 
Try to do this way to see if it works:
CType(readingsOnScreen(intloop), Object).Text = "1.00"
It shows all 1.00 on the screen

That's because the you're working with strings and not numbers
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

Open in new window

Ok that code in your last response worked. It still gave me only 1.00
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

Open in new window

It doesn;t go into the:
If Integer.TryParse(str, value) Then
                tmpsaved.Value = value.ToString("0.00")
            End If


loop??????
Can you show how you use it ?
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!
 
The code below. it doesn;t go into the  loop:
 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

Open in new window

That's because it's not a valid integer value.
What value are you using ?
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.
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
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial