Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

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
0answers
89 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 ...
7
votes
2answers
73 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 ...
3
votes
2answers
280 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
2answers
111 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 ...
4
votes
1answer
58 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 ...
3
votes
4answers
3k 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 ...
1
vote
1answer
869 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 ...
4
votes
3answers
226 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 : ...
7
votes
2answers
1k 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
2answers
306 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
votes
1answer
473 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 ...
7
votes
3answers
854 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
3answers
126 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
946 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
888 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
2answers
3k 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
1k 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
540 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 ...
2
votes
2answers
933 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
2answers
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. ...
4
votes
2answers
902 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
1k 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
380 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. ...
4
votes
3answers
901 views

Implementation of arbitrary-precision integer addition

Implementation: ...
4
votes
1answer
140 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
5k views

Is this a good isNaN method?

...
7
votes
2answers
1k 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
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
1answer
2k 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
202 views

Test if string is numeric

I want to implement the following function: ...