Data conversion in types such as int and double

Asked

Viewed 849 times

2

I’m having trouble making data conversions from a database, for example I perform a query to the bank like this:

carteira ca = bc.carteira.FirstOrDefault(obj => obj.cpf == cepf && obj.codigo == cod);

I receive information of the type ca.valor, ca.inicio, ... I wonder how to convert this value to a type like int, double,... In order to make the following additions:

int result;
double soma;
int x = ca.valor + result;  
double y = ca.inicio + soma;

And so I can use them in a method of my project

chama.meuMetodo(x,y); // x e y seriam int e double

I confess that I forgot how to make this conversion and the your Google is not helping.

  • 2

    You can post to us the Model of the object carteira?

  • hi I got it. I used the Convert class to do the conversions. for example: int Quant = Convert.Toint32(ca.qtdacao);

  • Is the answer below correct? If so, could you mark it as accepted, for the benefit of the community?

  • @user9090 what is the type of ca.qtdacao?

  • @user9090, the correct thing would be for you to publish your solution as Answer and mark it as correct, if that’s what you used to solve the problem. Check How and why to accept an answer?

1 answer

2


Try this on

Java

Double.parseDouble(x)
Integer.parseInt(x)

C#

Convert.ToDouble(x) 
Convert.ToInt32(x)
  • hi I got it. I used the Convert class to do the conversions. for example: int Quant = Convert.Toint32(ca.qtdacao); What was happening was that I was trying to convert ca and not the items of the object, I was trying: int x = Convert.Tint(ca); that way there was no way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.