-
-
Save careo/706986 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
int main (int argc, const char * argv[]) { | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
NSDecimalNumber *price = [NSDecimalNumber decimalNumberWithString:@"4.0"]; | |
NSDecimalNumber *paid = [NSDecimalNumber decimalNumberWithString:@"3.1"]; | |
NSDecimalNumber *result = [price decimalNumberBySubtracting: paid]; | |
//NSLog([result stringValue]); | |
NSLog(@"change = %@",[result stringValue]); | |
[pool drain]; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SquareChange { | |
def main(args: Array[String]) { | |
val price = BigDecimal("4.0"); | |
val paid = BigDecimal("3.1"); | |
val change = price - paid; | |
println("change = " + change); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
int dollars, cents; | |
float paid = 4.00f; | |
float price = 3.10f; | |
int paidInt = paid * 100; | |
int priceInt = price * 100; | |
int changeInt = paidInt - priceInt; | |
dollars = (float)changeInt / 100; | |
cents = changeInt % 100; | |
printf("change = %d.%d\n", dollars, cents); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* If you pay $4.00 for a latte that costs | |
* $3.10, how much change do you get? | |
*/ | |
int main() { | |
float change = 4.00f - 3.10f; | |
printf("change = %10.10f\n", change); | |
return 0; | |
} | |
// => 0.9000000954 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
float floating = 4.00 - 3.10; | |
printf("float = %10.10f\n", floating); | |
double doubled = 4.00 - 3.10; | |
printf("double = %10.10f\n", doubled); | |
printf("float size = %zu\n", sizeof(floating)); | |
printf("double size = %zu\n", sizeof(doubled)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment