0

Hello friends I Have a float type variable ,which contains a total price of specific item,so first I have converted into NSString..below is my code

float total;

[grandTotal setText:[NSString stringWithFormat:**@"$%.2f"**,total]];

so here grandTotal is of type UILabel..where I want the total in the format which I have written in the code

now again when i try to covert to do this

float previousTotal = [[grandTotal text] floatValue];

I am getting value of previousTotal = zero.

So I think their is issue with $ sign how to solve this is issue..

Rais Alam
  • 6,970
  • 12
  • 53
  • 84
Ranjit
  • 4,576
  • 11
  • 62
  • 121

2 Answers2

1

In your case you can solve it by using

float previousTotal = [[[grandTotal text] stringByReplacingOccurrencesOfString:@"$" withString:@""] floatValue];

But I think it is better to pass directly your float value.

iGranDav
  • 2,450
  • 1
  • 21
  • 25
0

I think its better to use

float previousTotal=total;

that is fare and simple.

Sathe_Nagaraja
  • 163
  • 1
  • 9