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.

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 ...
tommsch's user avatar
  • 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" ...
xyz9's user avatar
  • 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 ...
Mark Vincze's user avatar
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 ...
darkhorse's user avatar
  • 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 ...
Billy Watsy's user avatar
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 ...
atirit's user avatar
  • 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 ...
Hamatti's user avatar
  • 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 ...
gmail user's user avatar
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 ...
meyousikmann's user avatar
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 : ...
Luci's user avatar
  • 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 : ...
Julien Vernay's user avatar
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 ...
esote's user avatar
  • 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 ...
Ashwini Chaudhary's user avatar
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 ...
Thomas Johnson's user avatar
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 ...
Sam Orozco's user avatar
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:...
Owen's user avatar
  • 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: ...
random user 42's user avatar
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 ...
inuasha's user avatar
  • 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. ...
Justin's user avatar
  • 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 ...
Alex's user avatar
  • 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 ...
user avatar
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. ...
Shadow's user avatar
  • 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 ...
Assimilater's user avatar
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 ...
Elephants on Parade's user avatar
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. ...
Winplexy's user avatar
4 votes
3 answers
1k views

Implementation of arbitrary-precision integer addition

Implementation: ...
Rezo Megrelidze's user avatar
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 ...
Germann Arlington's user avatar
13 votes
3 answers
5k views

Is this a good isNaN method?

...
enon's user avatar
  • 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 ...
Germann Arlington's user avatar
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-...
Brian J. Fink's user avatar
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 ...
Brian J. Fink's user avatar
7 votes
2 answers
292 views

Test if string is numeric

I want to implement the following function: ...
Arun's user avatar
  • 171