help please!!!!

i want to create an windows phone application and i don't know how to convert from string in float......

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;


namespace Calculator_Full_Version
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void btnC_Click(object sender, RoutedEventArgs e)
        {
            
            string variabila;
            variabila = txtValue.Text;
            txtValue.Text = "";

        }

        private void btnStergere_individuala_Click(object sender, RoutedEventArgs e)
        {
            //here is the problem
            double variabila = 0.00;
            variabila = StrToFloat(txtValue.Text);
            
            
            
       
        }
    }
}
This is a C++ forum, btw, not C#

bool didConvert = double.TryParse(txtValue.Text, NumberStyles.Any, CultureInfo.InvariantCulture, variabila);
but is at section Windows programming not at general c++!
Yep, but have you read the title of this website?
closed account (z05DSL3A)
Welcome to this board wrote:
Welcome to the Windows forum in C++.com!

In this forum, users can to talk about any topic related to programming in C++ for the Windows platform.

Feel free to participate in a constructive and polite way in any topic of this category. Messages may be deleted or moved without prior notice and may prompt the suspension of user accounts.

Please notice that only registered users can post in this forum.
You can register for free at http://www.cplusplus.com/user/signup.cgi
An email address is required for confirmation, and a javascript-enabled browser to log-in and participate.


But anyway, use TryParse
1
2
3
4
5
    string text = "3.3";
    float number = 0;
    bool result = true;
    result = float.TryParse(text, out number);
    if(result....

ok, but the conversion is not work


"Error 1 Cannot implicitly convert type 'float' to 'string' C:\Users\ashmell\Documents\Visual Studio 2010\Projects\Calculator Full Version\Calculator Full Version\MainPage.xaml.cs 49 21 Calculator Full Version
"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Text.RegularExpressions;
using System.IO.IsolatedStorage;



namespace Calculator_Full_Version
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void btnC_Click(object sender, RoutedEventArgs e)
        {
            
            string variabila;
            variabila = txtValue.Text;
            txtValue.Text = "";

        }

        private void btnStergere_individuala_Click(object sender, RoutedEventArgs e)
        {
            //here is the problem
            //double variabila = 0.00;
            //variabila = StrToFloat(txtValue.Text);
            

    string variabila;
    variabila = txtValue.Text;
    float variabila_doi = 0;
    bool rezultat = true;
    rezultat = float.TryParse(variabila, out variabila_doi);
    txtValue.Text = variabila_doi;
    
            
            
            
       
        }
    }
}
closed account (z05DSL3A)
What is not working is the implicitly convert type 'float' to 'string' i.e. txtValue.Text = variabila_doi;. You could use the ToString() method on the float. i.e. txtValue.Text = variabila_doi.ToString();
Last edited on
Thanks is working!
Topic archived. No new replies allowed.