4,330 questions
1
vote
1
answer
159
views
Why do characters after %s in printf replace the starting characters
I'm learning C and trying to debug with printf calls.
But, when I format a string with %s and have characters immediately after, they end up replacing the characters at the beginning.
Example:
printf(&...
0
votes
1
answer
139
views
C++17 compiler warns "unknown conversion type character ‘.’ in format" for "%.12e" format string
I am updating some legacy code that is a mixture of C and C++. I am using a modern compiler (C++17) and building with Makefile. I get a warning for this line of code:
sscanf(data_buffer, "%d,%....
0
votes
2
answers
96
views
Why am I getting an extra space here?
air_temperature = float(input())
print('{:C>.1f}'.format(air_temperature), 'C')
Your output: 36.4 C
Expected output 35.4C
Error Message
Why am I being told there is an extra space here that is ...
0
votes
0
answers
46
views
What's the proper way to group each 3 characters with comma?
This Excel-like layout is implemented using RecyclerView.
For each EditTexts, the inputType is text because the requirement is to accepts these 2 formats:
Numeric input (separated by comma each 3 ...
1
vote
1
answer
120
views
Format np.float64 without leading digits
I need to format np.float64 floating values without leading digits before the dot, for example -2.40366982307 as -.240366982307E+01, in python.
This is to allow me to write in RINEX 3.03 the values ...
0
votes
0
answers
38
views
Streaming text from openai in next.js
"Streaming Text Formatting" – Formatting text that arrives in chunks from a stream.
"Real-time Text Structuring"
I am creating a web app using next.js and openai
When I use openai ...
0
votes
0
answers
28
views
XAML String format causes type not found error but works
I am working on some old XAML that has a binding with a string format specified as {}{0,8:0.000}
I believe the intent of this string format is to create a fixed length string with whitespace padding ...
1
vote
1
answer
130
views
Format number to a string such that spaces are inserted rather than 0s
When you convert some number to a string and pass in a format such as "00", it will insert 0's if the number doesn't have digits filling that spot. Example:
1.ToString("00") -> &...
1
vote
2
answers
122
views
Why aren't the string formats for the float equivalent, and why does "N9" produce a value that is different?
I would like to understand what is going on with this code:
float flt = 0.123F;
string s1 = flt.ToString("0.#########"); // "0.123"
string s2 = flt.ToString("N9"); ...
1
vote
1
answer
160
views
C++23 formatting mdspan as matrix
I'm trying to specify a formatter to print mdspan of rank 2 as a matrix, quite useful. I would like at least for element formatting to work, e.g. std::println("{::.2e}", matrix) would print ...
3
votes
1
answer
196
views
String representation of a tree (nodes) data structure with paths from left to right
Given a tree-like data structure of nodes with each node having a property children that contains the children nodes from left to right, I wish to create a string representation of this data structure ...
0
votes
2
answers
73
views
WPF TextBox typing issue with StringFormat
Is there a way to "bypass" the dot and "override" the decimals when typing a value in a TextBox in WPF formatted with a 2 decimals via StringFormat='{}{0:F2} ?
When I type "1....
-3
votes
3
answers
166
views
How to format printing an array in Python
I have an array of 10 elements and I can each of the elements print on a new line formatted 6.2f with
print(f'{myArray:6.2f}', sep="\n")
But I would like to create string containing what ...
0
votes
1
answer
298
views
How to format numbers with precision in strings when precision is only a runtime known value?
I have the following Zig snippet:
var buffer: [20]u8 = undefined;
const precise_string = std.fmt.bufPrint(&buffer, "{d:.d}", .{ max, precision }) catch unreachable;
std.debug.print("...
0
votes
1
answer
143
views
Query formula not grouping properly
I have a google sheet where one tab is the data entry sheet named "
Master Sheet". and I have another tab labeled "Charts/Tables". On the second tab I have a query pulling data ...
0
votes
0
answers
68
views
Printing a numpy variable with and without format gives different values
While working with numpy, I observed something strange. When I print a variable using print() and I format the print usingprint(f'{<variable>:.9f}) gives different values.
For example,
or
I am ...
0
votes
1
answer
653
views
ValueError: Space not allowed in string format specifier
I was modernizing some old % formatted string via regex substitution to change:
# Old:
'Map: % 20s' % name
# to New:
'Map: {: 20s}'.format(name)
and was surprised a
ValueError: Space not ...
1
vote
0
answers
76
views
Python formatting float to n signficaint digits
I would like to convert a set of floats to strings with 3 significant digits, e.g.
10.00 --> 10.0
10.10 --> 10.1
101.10 --> 101
Using "{:.3g}".format(x) results in 10, 10.1, 101 ...
-1
votes
1
answer
160
views
Why fmt.Println formats float64 values with different number of decimal places differently? [closed]
While I have checked the behavior of float64, I found the following behavior.
6 digits float64 variable's output is 100000.
7 digits float64 variable's output is 1e+06.
package main
import "...
4
votes
1
answer
153
views
Validate if a string matches a format string
In Ruby, you can parse a string into a DateTime based on a given format string, for example:
3.2.4 :001 > DateTime.strptime(Time.now.to_s, '%Y-%m-%d %H:%M')
Sat, 17 Aug 2024 13:31:00 +0000
3.2.4 :...
0
votes
2
answers
108
views
Dynamic size text columns formatting
I'm rewriting an old tool (which I don't have the original code) and one of the features is to print a list with filenames which his ID.
My goal is to get this result:
0 0x1A00000F
AAAAAAAAAAA ...
1
vote
1
answer
84
views
Is it possible to conditionally override levelname in formatting of Python logger?
I am currently working on some Python code that will be executed by a larger C# web project. The C# code uses NLog to create log files. I have got my Python logger logging to the same file. Also, I ...
0
votes
0
answers
71
views
WPF Custom Label
I have created a custom style for Labels in my application, this works fine and I apply a Template to achieve the other set styles that I need, again this works fine.
STYLE DEFINITIONS:
<Style ...
0
votes
1
answer
85
views
How would I format a string value from a custom list into money format?
I know this is likely a duplicate question and for that I am sorry. I have been looking for a way to format a custom string, that is pulling values from SQL database. I have read many S.O. on ...
-2
votes
1
answer
62
views
How to solve tabulations problem in WPF with C#
in C# I use the string.Format() function to get an output like this:
Of course, the problem is caused by the \t in this line:
string.Format("{0}\t\t{1}\t\t{2}...)
I tried various string.Format() ...
0
votes
1
answer
905
views
How to correctly and simply display multiline string literal in Jupyter Notebook?
I am looking for a solution that is the most convenient for casual, exploratory notebook use.
I have several functions that output strings with multiple lines. When this appears in the output cell of ...
1
vote
1
answer
108
views
How to use variable inside single quotation and placeholder in Snakemake shell
Here is a simplied rule for my problem
rule test:
output:
output_tex = expand("TPA_{region}.tex", region = [0,1]),
shell:
"""
for((i=0;i<2;i+...
2
votes
3
answers
2k
views
How can I make certain text bold in Python string formatting?
I have a snippet where I generate a string that includes an original number (original_number) and its corresponding Roman numeral (roman_number). I want to format this string so that the original ...
3
votes
2
answers
258
views
Most efficient way to convert a hex string value in Java with format
I have the following Java code that increases the value of a hex value and returns a string using the following format (where x is an increasing hex value and 7 is a literal):
xxxx-7xxx-xxxx
The ...
0
votes
1
answer
143
views
Formatting specific rows in Pandas Dataframe with string formatting and heatmap
Here I have a code for a function that creates a formatted table.It currently works but I want to optimise it considering "Setting an item of incompatible dtype is deprecated and will raise an ...
-1
votes
1
answer
155
views
Formating a float/double to scientific notation or Si units
I am trying to make a seemingly simple piece of code that I am unable to get working.
It takes a double (or float) and formats it to a string in a specific way: E.g. 13.453.123,25 (Dots for thousands, ...
0
votes
1
answer
633
views
MAUI XAML Label with Different Font size
I need a label to show a number in the range of thousands. I'm not using thousand separator as per requested, but I want the user to be able to focus on the thousands. For example if I were to show &...
1
vote
1
answer
66
views
How to set datagridview and datarow cell format when editing and after editing from datatable in vb.net
I'm Trying to set datagridview and datarow cell format when editing and after editing from datatable in vb.net.
Is it possible for the Price column to still use string.empty after editing so it ...
0
votes
3
answers
712
views
Strings are printed like integer with scientific notation in python
a=str(141528231211101319151414.0)
print(a)
# 1.4152823121110133e+23
This string was printed with scientific notation. I do not understand why.
I am using mpmath to deal with arithmetic operations ...
0
votes
3
answers
202
views
What is a simple way to round all floats in an f-string to the same number of digits in one step?
I have a long f-string with containing many float values, all of which I want to round to the same number of digits. Is there a way to do this in one go or in a smart way, or do I need to specify the ...
0
votes
1
answer
152
views
How to format float to omit zeros at the end of the fraction
I'd like to format a float so that it has at most 3 fractional digits, but if the last fractional digit(s) are 0 then omit them.
input : expected output
1.1234 : 1.123
1.120 : 1.12
1.100 : 1.1
1.0 : 1
...
-2
votes
1
answer
101
views
WPF TextBox set common StringFormat for all controls
Is it possible to make something to set StringFormat of Binding property for all (or part of) TextBoxes in project? Yes, I can write something like
<TextBox x:Name="SetPosition" Style=&...
3
votes
2
answers
265
views
Powershell is not recognising a date that has been formatted in datetime format
I am searching Splunk using powershell via API and get a list of data that contain dates (not in DateTime format).
The API call is performed by a Function that works fine and it works for the inital ...
-1
votes
1
answer
212
views
How to do string interpilation in R [duplicate]
Basically the function where you add a variable inside a string like the JavaScript template literals:
var str = "This is a sample";
print(`So you load the string in with ${str}, and it ...
-3
votes
1
answer
167
views
How do I return True if a string in a cell is contained anywhere in a column?
I am working in google sheets. Excel also works.
I have column called "funds." This column has names of venture funds, such as Accel, A16z, and Sequoia. One fund in each row.
I have another ...
1
vote
1
answer
183
views
Error when trying to deploy my ping command(discord bot)
I'm following code from a channel on YT and im given this error and cant figure out how to resolve it.
This is the error
ExpectedConstraintError: Invalid string format
at Object.run (C:\Discord Bot\...
0
votes
3
answers
785
views
Use str.format to format numbers with a minimum of 1 decimal place without rounding and without adding additional trailing zeroes
Context
I am receiving numbers as strings in Python 3 and want to transmit them as strings in order to preserve accuracy so that the upstream server can convert the numbers-as-strings to decimal....
-1
votes
1
answer
359
views
How to Format Lists of Strings and Dictionaries for Email Body in Python
I'm working on a Python script where I need to format three different types of lists into a string that will be used as the body of an email. The lists are as follows:
A list of strings:
a = ['1.1.1.1'...
0
votes
1
answer
129
views
Tuple unpacking to formatted string in Python
I have been working though Fluent Python 2nd Edition by Luciano Ramalho.
On page 5 he writes that he has attempted to adopt the f string syntax throughout the book, although there are times when str....
0
votes
0
answers
53
views
R doesn't allow me to define the number of columns I want my header to spawn
I made a R-script and build several html tables with kablExtra. I made 4 tables. I forgot to make a header for the 3th. So I tried to make a header for the third with this code:
#### Set GLOBAL ...
0
votes
2
answers
583
views
C# String Format for Scientific Notation if greater than a certain number of digits
I have a series of numbers that can be either large integers, or very small decimals. I would like numbers with more than four digits to be displayed in scientific notation.
At first, I considered a ...
3
votes
1
answer
3k
views
How to use the new CompositeFormat class from .NET 8.0?
I'm testing migrating a .NET 6.0 application to .NET 8.0, and the following piece of code now throws CA1863 "Use 'CompositeFormat'". But I don't know how.
private const string ...
1
vote
1
answer
131
views
Is a formatted string still a string? Is it still printable, or it is just a bunch of rules?
I am looking at other code on a Java practice. Here is his code:
import java.util.Arrays;
import java.util.stream.Collectors;
public class StripComments {
public static String stripComments(...
1
vote
1
answer
91
views
Lua formatting returns unexpected results
I recently wrote a small program where I'm trying to convert a number of seconds into a more human readable format, but I'm having problems when trying to format the output and somehow I end up ...
-1
votes
1
answer
189
views
Learning python Python TypeError: not enough arguments for format string [duplicate]
I am new to python and trying to learn the basic
just learned how to format string today and couldn't figure out what is wrong with this line of codes
data = ["Zac", "poor fella", ...