Reputation: 1147
I am writing an application in C (under Linux) which deals with prices. The program receives price quotes in a form of integer pairs (m, e) so that the resulting price is simply 'm * 10^e'.
I'd like to be able both manipulate the prices with arithmetical operations and use "printf"-like functions for formatting output. I have to do that pretty fast.
What is the fastest way dealing decimals in C? I've read about Decimal Floats in gcc, but their lack of libc support makes them impossible to use in a standard way. Thank you.
Upvotes: 0
Views: 190
Reputation: 6037
If your prices are always at the most to 2 decimal places then you can just use integers to represent the number of cents. printf is also simple with
printf("%d.%02d", price/100, price%100 );
Upvotes: 1