Skip to main content
Share Your Experience: Take the 2024 Developer Survey

# Questions tagged [fixed-point]

Fixed point arithmetic is done using a set number of decimal places. It can be faster and is more precise than floating-point.

32 questions
Filter by
Sorted by
Tagged with
3 votes
2 answers
674 views

### Fixed Point Type

I am implementing a fixed point type, which mostly is used to be able store numbers as multiples of some base (power of 2). Apart from that, the type should be able to replace double/float values ...
• 243
0 votes
3 answers
259 views

### Fractional binary number to decimal number

Write and test your own double abc (char * b) function in the program, taking in the form of a string the fractional binary number of the form "1101.101" ...
• 21
4 votes
0 answers
792 views

### Java code to convert BigDecimal to/from .NET decimal

Background In many languages we have built-in data types for representing decimal floating point numbers. In .NET that's decimal, and in Java we have ...
• 161
7 votes
2 answers
313 views

### Method for formatting a decimal number in Python using the given maximum number of digits and decimal places

The question itself should be fairly self-explanatory. My method takes in value, max_digits, and ...
• 418
3 votes
2 answers
940 views

### Adding thousand separator to various number types

Am making a pure .net library with helper functions (GitHub). However I wanted to have a thousand separator for all number types and here is what I am currently doing ...
1 vote
2 answers
190 views

### Converting a String to USD

I'm working on a clientside iOS app for my school that involves students purchasing things, and I wrote a String extension for formatting a ...
• 225
4 votes
1 answer
180 views

### Enforcing numeric inputs and sanitizing different formats for IE11 input fields

I'm working on a web form that functions with numeric inputs. I have <input type="number"> input fields and with Chrome and Firefox things work nicely since ...
• 171
3 votes
4 answers
4k views

### Convert decimal to string

I wrote a C# program that converts decimal to string. It is not the best but it works. I'm looking for inputs from others on how ...
• 237
1 vote
1 answer
2k views

### Convert decimal currency to an integer

I have some code that is used to convert a decimal currency to an integer with precision being a function of which currency is being converted. This code is more of a "brute-force" method to do the ...
• 113
4 votes
3 answers
494 views

### Formatting the opposite of some numbers, with decimal alignment

Background I have a list of strings containing numbers. Each string is 8 characters long. For example : ...
• 225
7 votes
2 answers
2k views

### Fixed Point Arithmetics in C++ using templates

I am trying to create a Fixed Point Arithmetics library : I call fixed point a number which has bits reserved for decimal part. Here is the code : ...
7 votes
2 answers
354 views

### Calculating a ton of mathematical constants

For a while now I have been working to construct a program to calculate a lot of mathematical constants. Before I explain, here's the code: Code ...
• 3,770
3 votes
1 answer
837 views

### Indian numbering system formatting

The following code converts a number into Indian numbering system format. I know locale can also help in getting similar format but I wanted something that can work on any system because not all ...
• 3,095
7 votes
3 answers
2k views

### String formatting for uint64_t that represents a fixed-point decimal

My goal is to take a uint64_t that represents a fixed-point decimal, and output a string representation of the decimal. The fixed-point representation always has ...
3 votes
3 answers
300 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 ...
• 228
3 votes
3 answers
1k 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,494
1 vote
0 answers
1k 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: ...
3 votes
2 answers
7k 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 ...
• 33
0 votes
1 answer
3k 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,295
3 votes
2 answers
906 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 ...
• 353
3 votes
2 answers
1k 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 ...
3 votes
2 answers
1k 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. ...
• 643
4 votes
2 answers
978 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 ...
• 315
5 votes
2 answers
2k 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
2 answers
515 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. ...
• 91
4 votes
3 answers
1k views

### Implementation of arbitrary-precision integer addition

Implementation: ...
• 1,121
4 votes
1 answer
146 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 ...
13 votes
3 answers
5k views

...
• 387
7 votes
2 answers
2k 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
1 answer
1k 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
1 answer
3k 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
2 answers
292 views

### Test if string is numeric

I want to implement the following function: ...
• 171