Method

# CStr

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Use to convert the passed data type to a `String</api/data_types/string>`. Numbers are formatted using the system settings for numerical display.

## Usage

``` xojo
result = CStr(data)
```

| Part   | Type                               | Description                                        |
|--------|------------------------------------|----------------------------------------------------|
| result | `String</api/data_types/string>`   | The string representation of the value passed.     |
| data   | `Variant</api/data_types/variant>` | The variable that will be represented as a string. |

## Notes

You can pass a class instance as long as the class implements the `Operator Convert</api/language/operators/operator_overloads/operator_convert>` method that returns a `String</api/data_types/string>`.

For real numbers, <span class="title-ref">CStr</span> returns 7 significant digits. When you pass a real number to <span class="title-ref">CStr</span>, the string it returns uses the decimal separator the user specified in system preferences. However, in most cases you will want to use the `Format</api/text/format>` function instead for more precise control of the formatting. Use the `Str</api/text/str>` function if you want to ensure US/English notation.

If you pass a `Boolean</api/data_types/boolean>`, <span class="title-ref">CStr</span> will return either the string "True" or "False". If you pass a `Color</api/data_types/color>`, it will return the hex representation of the color as a `String</api/data_types/string>`. If you pass a `DateTime</api/data_types/datetime>`, it will return the value of the date in SQL Date-time format.

## Sample code

This code returns the string representation of two numbers and a `Boolean</api/data_types/boolean>`.

``` xojo
Var s As String
Var d As DateTime = DateTime.Now
s = CStr(1) ' returns "1", as a string
s = CStr(d.Day) ' returns the day number as a string
s = CStr(True) ' returns "True"
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This code returns the approximation to Pi as a `String</api/data_types/string>` to 7 significant digits.

``` xojo
Var s As String
Const kPi = 3.14159265358979323846264338327950
s = CStr(kPi) ' returns "3.141593"
```

## Compatibility

|                       |                       |
|-----------------------|-----------------------|
| **Project Types**     | Console, Desktop, Web |
| **Operating Systems** | All                   |

<div class="seealso">

`Format</api/text/format>`, `String.ToDouble<string.todouble>`, `Str</api/text/str>`, `Val</api/text/val>` functions; `Boolean</api/data_types/boolean>`, `Color</api/data_types/color>`, `DateTime</api/data_types/datetime>`, `String</api/data_types/string>`, `Variant</api/data_types/variant>` datatypes

</div>
