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
cmdolcetAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

format(1,"0.00")
0
cmdolcetAuthor Commented:
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)
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Jorge PaulinoIT Pro/DeveloperCommented:
Try this way
 
 

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

Open in new window

0
cmdolcetAuthor Commented:
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

0
Jorge PaulinoIT Pro/DeveloperCommented:
It should be
tmpsaved.Value = tmpsaved.Value.ToString("0.00")

 
0
cmdolcetAuthor Commented:
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

0
Jorge PaulinoIT Pro/DeveloperCommented:
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"
0
cmdolcetAuthor Commented:
It shows all 1.00 on the screen

0
Jorge PaulinoIT Pro/DeveloperCommented:
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

0
cmdolcetAuthor Commented:
Ok that code in your last response worked. It still gave me only 1.00
have do I get the actual value?
0
Jorge PaulinoIT Pro/DeveloperCommented:
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

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


loop??????
0
Jorge PaulinoIT Pro/DeveloperCommented:
Can you show how you use it ?
0
cmdolcetAuthor Commented:
What do you mean I showed how I used it above?
0
Jorge PaulinoIT Pro/DeveloperCommented:
What do you mean with "It doesn;t go into the" ? I don't understand that!
 
0
cmdolcetAuthor Commented:
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

0
Jorge PaulinoIT Pro/DeveloperCommented:
That's because it's not a valid integer value.
What value are you using ?
0
cmdolcetAuthor Commented:
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?
0
Jorge PaulinoIT Pro/DeveloperCommented:
>> Im using the tmpsaved.Value which is a string value
Ok, but what value ... give an example.
0
cmdolcetAuthor Commented:
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
0
Jorge PaulinoIT Pro/DeveloperCommented:
Ok, Gotcha!
Integer values only allow non decimal numbers. You have to use Decimal

            Dim str As String = tmpsaved.Value
            Dim value As Decimal
            If Decimal.TryParse(str, value) Then
                tmpsaved.Value = value.ToString("0.00")
            End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.