Skip to main content

All Questions

Tagged with
-2 votes
2 answers
69 views

How to print a list of float64 with justified decimal point in Go

I would like to print a slice of float64 values line by line having all decimal points at the same position in each line. I could print the integer part right justified, the decimal point and then the ...
Thomas Höhenleitner's user avatar
5 votes
1 answer
264 views

How do I convert a `float` to a `_Float16`, or even initialize a `_Float16`? (And/or print with printf?)

I'm developing a library which uses _Float16s for many of the constants to save space when passing them around. However, just testing, it seems that telling GCC to just "set it to 1" isn't ...
Coarse Rosinflower's user avatar
1 vote
2 answers
96 views

How to combine significant figures, column width, and alignment specifiers?

I would like to print doubles with consistent column width. Theses numbers represent dollar values so I would also like to have no more than two digits after the decimal print. Here I'm intending to ...
Gideon's user avatar
  • 19
1 vote
1 answer
132 views

bash printf broken for floats

I have a bash script that gets battery information. Here's part of it: #!/bin/bash if [ -f /sys/class/power_supply/BAT0/energy_full ]; then EF=$( echo $(cat /sys/class/power_supply/BAT0/energy_full)...
JFBonzo's user avatar
  • 13
1 vote
1 answer
112 views

Why isn't printf printing a float passed by a variable? [duplicate]

Why is the following: int main(void) { double b = 11/2; double a = 2; printf("%lf\n", a + b); printf("%lf\n", b); } printing, respectively, 7.000000 and 5.000000 I ...
Guilherme Cintra's user avatar
2 votes
1 answer
111 views

How do you support both doubles and long doubles without changing format specifiers?

I was able to compile xnec2c with long double's by simply search-replacing double with long double. It calculates correctly, except anywhere that a format specifier is used because it wants %Lf... ...
KJ7LNW's user avatar
  • 1,951
1 vote
1 answer
87 views

Trouble with getting a function to calculate and loop correctly in C

I am needing to make a program to take user input of iterations to the formula : PI=4(1/1 -(1/3)+(1/5) ... repeating a number of times. MY problems so far is that it is not taking my input accurately. ...
Spongebuild's user avatar
0 votes
2 answers
223 views

Using %f but get "format %f expects type double"

Unless I'm tired I do not understand the following warning. I am not sure what the compiler is based on (it's MPLAB X 6 using XC16 from Microchip for a dsPIC33 microcontroller). float test=5.5; printf(...
dargaud's user avatar
  • 2,591
2 votes
3 answers
586 views

What is the maximum string length for %g float representation?

How big does a stack allocated string need to be in order to store any float/double in %g format? int main() { float f; double d; char f_str[ ?? ]; char d_str[ ?? ]; ...
Abdulmalek Almkainzi's user avatar
1 vote
2 answers
95 views

How to compute precision for conversion specification %.*f to maintain precision of floating-point value?

Note: this question originated from this answer. How to compute precision for conversion specification %.*f to maintain precision of floating-point value? Note: Here the "maintain precision" ...
pmor's user avatar
  • 6,530
6 votes
2 answers
203 views

Interpreting the format specifier in printf("%# 01.1g",9.8)

Consider the following printf instruction: printf("%# 01.1g", 9.8); what should it print? I'm reading the description of the g specifier on cppreference.com, which says (text for G removed):...
einpoklum's user avatar
  • 133k
5 votes
0 answers
169 views

How to round float numbers in Haskell just like in C using printf?

I have a simple code to read a float number and print it with six decimal places. I have my C code working and I want to make an equal one to Haskell language without installing any extra library. My ...
eightShirt's user avatar
  • 1,447
2 votes
1 answer
509 views

How to use scanf to read a floating point value in nasm x86 64?

I'm trying to simply read a floating point value and print it using assembly x86 64. So, the value for the variable price, which I'm using as the buffer for the c function scanf doesn't change when I ...
Jonas's user avatar
  • 454
2 votes
3 answers
273 views

Longest possible %a string for floats and doubles?

When using the %a specifier with the printf family of functions, what is the longest possible string that results for a float and for a double? Assume that float and double are IEEE-754 32-bit and 64-...
Costava's user avatar
  • 401
1 vote
1 answer
232 views

How can I printf() a float in hexadecimal form?

In C we can produce hexadecimal floating point literals and we can also use printf() to output them in decimal string form: printf("%f\n", 0x1.0p8); // Prints 256.00000 How can I output a ...
CPlus's user avatar
  • 4,941

15 30 50 per page
1
2 3 4 5
15
X