问题标签 [format-specifiers]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c - 如何防止浮点/双精度格式说明符自动更改 C 中的十进制值?
我有一个奇怪的问题,如果我输入 720.60 到
其中 amount 是 float 类型,变量中的值更改为 720.59967。
我怎样才能绕过它并防止它改变我的价值?
c++ - sprintf 由于参数变量中的 %s 而崩溃
我有一个 sprintf 命令,由于 aurgument 变量中的 %s 而崩溃。除了用 %% 转义参数字符串之外,建议的解决方法是什么。
任何帮助将不胜感激。
c++ - Why we don't use format specifiers with cout?
When we use printf then we use format specifiers (such as %c,%p) but when we use cout we don't use them why and what is being done in background because which we are not using them ?
I know they are used in differently in c and c++ but still i want to know how formatting is being done in cout, while it is done in printf through format specifiers.
c - float * 和 int * 的不同 printf 行为?
首先,让我澄清一下,我知道将指针作为参数传递给这些printf
说明符是不正确的。然而,我有兴趣知道printf
它完成后会发生什么。
使用普通的打印说明符%d
forint
和%f
for float
,为什么是int *
打印,而float *
不会呢?
例如,给定这些变量(未初始化):
当这样调用时:
为什么我会得到这个?:(“a”打印正常,但“b”仅使用 %p 或通过 *b 打印)
[编辑] 整个代码以澄清和解决一些评论问题:
***[编辑 2] 如果取消注释 3rd printf,则解决有关实际内容的一些评论
我收到以下两个运行时通知,然后在第 3 行中没有得到 printf 的输出:
c - “%-9s”是做什么的?
我正在开发一个 C 项目,现在使用开源方法集成到我的代码中。在浏览代码时,我遇到了这样的printf语句:
我了解格式说明符%s但什么是%9s?
我试图为此寻找解决方案,但没有成功。任何帮助都会很有用。
ios - 如何在给定整数时不显示不必要的零,但在需要时仍然有浮点答案
我有一个正在开发的应用程序,我的一个功能是在需要时以浮点值或双精度值给出答案,当答案是整数时给出整数
因此,例如,如果答案为 8.52,则答案变为 8.52,但当答案为 8 时,答案为 8 而不是 8.0000,我不希望它显示所有额外的 0。
这段代码似乎不起作用
c - printf() 中的格式说明符要求 int 何时应为 char
我正在使用 Pelles C ide 并且正在学习 C,我以为我了解到 %c 是 printf() 中 char 的格式说明符,但它认为我正在尝试使用 int?我该如何纠正这个问题。
这是代码:
}
这是错误:
objective-c - Is it clean/safe to type cast just with the format specifier and assignment operator in Objective-C?
In Objective-C, is it a clean/safe approach to type cast let's say, a floating-point number to an integer with just assigning the floating-point variable to the int variable, and with the format specifier %i in NSLog call?
The proper way to do this is declaring the type cast like this:
Output:
The value of x is 7
This type-casting method would be the ideal approach, but I tried to just assign the floating-point variable into the int variable and it works the same, is there a difference?
This is the other method without the (type-cast):
Output:
The value of x is 7
As you can see, is the same result, what's the difference? both methods are good? which is cleaner?
c - c 中的 %*d 是什么?
我遇到了一个代码:
它输出:n= 5
。我知道这%*d
允许两个参数并返回字段宽度。但是,我尝试将n
' 值更改为9
. 但输出格式相同(即n= 9
)。另外,我不是 100% 确定我理解%*d
正确和字段宽度。
因此我的问题是%*d
,C 中的字段宽度是什么?
谢谢。
编辑:
好的,谢谢大家。我现在明白了,是我的编译器将空格合二为一。
c - 使用宏转换打印语句
我在我的代码中多次使用了一种类型的调试语句——比如说DEBUG("abcd");
或者DEBUG("abc %d def", val)
被翻译并打印到文件中。
现在,但是我想将它们全部转换为不同类型的日志记录,这需要使用带有声明的函数,例如 -
用法:WRITE(L"abcd")
等等。因为这个调试语句的使用量很大,我希望用宏来转换它。可以这样做吗?还考虑到DEBUG
用于接受格式说明符的函数呢?