Fixed point arithmetic is done using a set number of decimal places. It can be faster and is more precise than floating-point.
3
votes
3answers
72 views
Java number formatting in accountant style
I have written a string number formatter. I would like to know if this can be improved and any suggestions with how it's done.
The purpose of this function is to convert a double that has been ...
3
votes
3answers
82 views
Divide decimal by range of fractions, and then convert the fraction that is closest to a whole number to a mixed fraction
My program will divide the decimal (\$30.0575\$) by a range of fractions (\$\frac{1}{1}, \frac{1}{2}, \frac{1}{4}, \dots, \frac{1}{48})\$ leaving me with list of improper fractions that look like this:...
1
vote
0answers
81 views
Handle decimal in mongodb
I'm trying to find a way to handle decimals in mongodb. Is there any good way and/or should I handle it with a class like this:
...
2
votes
2answers
250 views
Counting significant figures in a number
I decided to make something to count the significant figures in a number to see how easily it could be done, but I think there may have been a better or simpler way. Any advice even just for ...
0
votes
1answer
230 views
Fixed Point Number to String
I recently learned about using fixed point arithmetic on embedded systems without floating point hardware, so I decided to code it. I tried to write in good style, but emphasized speed over style.
...
3
votes
2answers
94 views
BigDecimal wrapper that ignores zero operands
I want to perform mathematical operations on a range of values, where zeros should be ignored. This means that multiplication by zero does not result in zero but returns the first operand and likewise ...
1
vote
2answers
196 views
Rounding prices
I have written a PHP function that should round prices to a desired format.
E.G. 1547.86456
That should be : 1547.85
OR
if desired : 1547.86
The code has been written and it works under several ...
2
votes
2answers
276 views
Decimal expansion of a rational number
I wrote a program that does division and either does or doesn't show repeating groups. After designing it the first time I had to redesign it because although it worked it was unnecessarily complex. ...
4
votes
2answers
220 views
Storing currency-precision values
I'm trying to develop a program that stores currency values. In my particular application I only care about two decimal of precision (cents) but have read it's a good idea (for accuracy when dealing ...
4
votes
2answers
304 views
Java helper function to round a number to the specified number of decimal places
The function I need:
Rounds a double to the specified number of decimal places
I figured this would be a part of java.lang.math, but inexplicably it doesn't ...
3
votes
2answers
218 views
Cut float numbers in a stream (putchar, getchar) and in a string
For example, the following row:
"a+12.3456-b-0.456789+1.3-45678"
will be transformed into
"a+12.34-b-0.45+1.3-45678"
That is, we need to cut out the figures after the point from the third figure. ...
3
votes
3answers
475 views
4
votes
1answer
97 views
BigDecimal made Simple - take 2
Following all comments on my original post:
BigDecimal made Simple
The following interface was derived from functionality provided by (mainly) Bigdecimal and is ...
12
votes
3answers
3k views
7
votes
2answers
539 views
BigDecimal made simple
Here is my take on (a lighter version of) Java's BigDecimal. I originally wrote this as a replacement for BigDecimal in order to ...
4
votes
1answer
644 views
Followup: How do I optimize this Java cube root function for BigInteger?
Followup to How do I optimize this Java cube root function for BigInteger?
So I've tried several implementations of this algorithm. The version using only BigInteger sometimes results in a never-...
7
votes
1answer
836 views
How do I optimize this Java cube root function for BigInteger?
I find that this function is one of the biggest causes of slow program execution. I can write a square root version with BigInteger only, but with the cube root, the algorithm sometimes gets caught in ...
7
votes
2answers
160 views