FROM : C Sandeep
DATE : Tue Feb 26 21:47:30 2008
Hi all,
Thanks for the ideas. Im using the class method to evaluate such
strings, thusly:
-(NSNumber *) getNumberFrom: (NSString *) str {
NSScanner *scanner = [NSScanner scannerWithString: str];
int numerator, denominator;
[scanner scanInt: &numerator];
[scanner scanString:@"/" intoString: NULL];
[scanner scanInt: &denominator];
float result = (float) numerator/denominator;
NSNumber *nm = [NSNumber numberWithFloat: result];
return nm;
}
- Sandeep
On Tue, Feb 26, 2008 at 1:27 PM, Hamish Allan <<email_removed>> wrote:
> On Tue, Feb 26, 2008 at 6:12 PM, Jean-Daniel Dupas
> <<email_removed>> wrote:
>
> > As far as I know, there is no Math expression parser buit-in Cocoa.
> > You will have to write your own evaluator to do this.
>
> Or use e.g. NSTask with 'bc' (remembering to specify a scale for bc).
>
> Hamish
>
DATE : Tue Feb 26 21:47:30 2008
Hi all,
Thanks for the ideas. Im using the class method to evaluate such
strings, thusly:
-(NSNumber *) getNumberFrom: (NSString *) str {
NSScanner *scanner = [NSScanner scannerWithString: str];
int numerator, denominator;
[scanner scanInt: &numerator];
[scanner scanString:@"/" intoString: NULL];
[scanner scanInt: &denominator];
float result = (float) numerator/denominator;
NSNumber *nm = [NSNumber numberWithFloat: result];
return nm;
}
- Sandeep
On Tue, Feb 26, 2008 at 1:27 PM, Hamish Allan <<email_removed>> wrote:
> On Tue, Feb 26, 2008 at 6:12 PM, Jean-Daniel Dupas
> <<email_removed>> wrote:
>
> > As far as I know, there is no Math expression parser buit-in Cocoa.
> > You will have to write your own evaluator to do this.
>
> Or use e.g. NSTask with 'bc' (remembering to specify a scale for bc).
>
> Hamish
>
| Related mails | Author | Date |
|---|---|---|
| C Sandeep | Feb 26, 18:55 | |
| Randall Meadows | Feb 26, 19:11 | |
| Jean-Daniel Dupas | Feb 26, 19:12 | |
| Hamish Allan | Feb 26, 19:27 | |
| C Sandeep | Feb 26, 21:47 | |
| j o a r | Feb 26, 23:10 | |
| Graham | Feb 26, 23:42 |






Cocoa mail archive

