[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

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
0
cmdolcet
Asked:
cmdolcet
  • 10
  • 10
  • 2
1 Solution
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jpaulinoCommented:
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
 
jpaulinoCommented:
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
 
jpaulinoCommented:
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
 
jpaulinoCommented:
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
 
jpaulinoCommented:
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
 
jpaulinoCommented:
Can you show how you use it ?
0
 
cmdolcetAuthor Commented:
What do you mean I showed how I used it above?
0
 
jpaulinoCommented:
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
 
jpaulinoCommented:
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
 
jpaulinoCommented:
>> 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
 
jpaulinoCommented:
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

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 10
  • 10
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now