# Problem with CStr()

**URL:** <https://tech-community.robotics.abb.com/t/problem-with-cstr/1261>\
**Category:** Developer Tools\
**Created:** [June 12, 2007, 12:04pm UTC](https://tech-community.robotics.abb.com/t/problem-with-cstr/1261 "2007-06-12T12:04:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PerM](https://avatars.discourse-cdn.com/v4/letter/p/a88e4f/32.png) [@PerM](https://tech-community.robotics.abb.com/u/PerM)\
**Post date:** [June 12, 2007, 12:04pm UTC](https://tech-community.robotics.abb.com/t/problem-with-cstr/1261/1 "2007-06-12T12:04:37Z")

</div>

Hi,

I’m Experimenting with the Flexpendant.

I’m having some problem converting values between double and string. I have used the following two lines to try and see what happens:

tempDouble = 12.45

TpsLabel4.Text = CStr(tempDouble)

The resulting string is then converted to: “12,45” it should be: “12.45”.

Why is this?

/perM

---

<div class="post-metadata">

**Author:** ![RussD](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@RussD](https://tech-community.robotics.abb.com/u/RussD)\
**Post date:** [June 12, 2007, 3:30pm UTC](https://tech-community.robotics.abb.com/t/problem-with-cstr/1261/2 "2007-06-12T15:30:21Z")

</div>

It looks like it is using a localized format to display the value, are you using a non-english version of Vsual Studio, do you have additional languages enabled in your RobotWare system?

---

<div class="post-metadata">

**Author:** ![PerM](https://avatars.discourse-cdn.com/v4/letter/p/a88e4f/32.png) [@PerM](https://tech-community.robotics.abb.com/u/PerM)\
**Post date:** [June 12, 2007, 3:37pm UTC](https://tech-community.robotics.abb.com/t/problem-with-cstr/1261/3 "2007-06-12T15:37:37Z")

</div>

The Windows language is Swedish, the Visual Studio Installation is English, the System in the Virtual Flexpendant is English.

I Managed to make a workaround for now. I made a “ChangeCharacter” function that I use before and after conversion, to make sure i have the correct decimal character.

it seams to work for now.

But it would be nice to now why there is a problem to begin with.

/PerM

---

<div class="post-metadata">

**Author:** ![RussD](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@RussD](https://tech-community.robotics.abb.com/u/RussD)\
**Post date:** [June 12, 2007, 4:05pm UTC](https://tech-community.robotics.abb.com/t/problem-with-cstr/1261/4 "2007-06-12T16:05:20Z")

</div>

Can you use tempDouble.ToString?

---

<div class="post-metadata">

**Author:** ![John\_Wiberg](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/john_wiberg/32/1485_2.png) [@John\_Wiberg](https://tech-community.robotics.abb.com/u/John_Wiberg)\
**Post date:** [June 18, 2007, 6:49pm UTC](https://tech-community.robotics.abb.com/t/problem-with-cstr/1261/5 "2007-06-18T18:49:35Z")

</div>

CStr always take your regional settings into consideration. Instead in .NET it is customary to use the ToString method which is overloaded to define whatever formatting that you want.

Here is an example code, create a Windows form and add three buttons

Button1 is using CStr which will use the seperator defined by your culture  
Button2 will use _._  
Button3 will use _,_

> Imports System.Globalization  
> Public Class Form1  
> Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
> Dim myDouble As Double  
> myDouble = 12.345  
> Button1.Text = CStr(myDouble)  
> End Sub
> 
> Private Sub Button2\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click  
> Dim myDouble As Double  
> myDouble = 12.345  
> Dim x As New NumberFormatInfo  
> x.NumberDecimalSeparator = “.”  
> Button2.Text = myDouble.ToString(x)  
> End Sub
> 
> Private Sub Button3\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click  
> Dim myDouble As Double  
> myDouble = 12.345  
> Dim x As New NumberFormatInfo  
> x.NumberDecimalSeparator = “,”  
> Button3.Text = myDouble.ToString(x)  
> End Sub
> 
> End Class
