.NET字符串格式化 - 小数点左边的#是什么意思?(.NET String formatting -What does the # mean to the left of the decimal point?)
我需要将数字字符串格式化为小数点两边最多2个位置,即使这意味着截断或截断前导数字(这是一个很长的故事,不要问)。 在MSDN上,它暗示可以使用井号(#)完成:
“”#“自定义格式说明符用作数字占位符符号。如果格式化的值在格式字符串中出现井号的位置有一个数字,则该数字将复制到结果字符串。否则,没有任何东西存储在结果字符串中的那个位置。“
但在实践中,似乎只能在小数点右侧工作。 如果我这样做:
String s = " Test - " + String.Format("format0 = {0:0.##}, format1 = {1:#.##}, format2 = {2:##.###}",321.2345, 321.2345, 321.2345);
我得到s的这个输出:
“测试 - 格式0 = 321.23,格式1 = 321.23,格式2 = 321.235”
...注意“0。##”和“#。##”产生相同的输出。 那么当它位于小数点左侧时,“#” 究竟是什么意思呢?
I have a need to format a numeric string to a maximum of 2 places either side of the decimal point, even if it means truncating or chopping off the leading digits (it's a long story, don't ask). On the MSDN it implies this can be done with the pound sign (#):
"The "#" custom format specifier serves as a digit-placeholder symbol. If the value that is being formatted has a digit in the position where the pound sign appears in the format string, that digit is copied to the result string. Otherwise, nothing is stored in that position in the result string."
But in practice that only seems to work to the right of the decimal point. If I do this:
String s = " Test - " + String.Format("format0 = {0:0.##}, format1 = {1:#.##}, format2 = {2:##.###}",321.2345, 321.2345, 321.2345);
I get this output for s:
" Test - format0 = 321.23, format1 = 321.23, format2 = 321.235"
... note that "0.##" and "#.##" produced the same output. So what exactly does the "#" mean when it's to the left of the decimal point?
原文:https://stackoverflow.com/questions/20707973
最满意答案
尝试使用
android:includeFontPadding="false"
来查看是否有帮助。 它会有所帮助,但是没有办法将TextView尺寸缩小到完全像素完美的文本尺寸。唯一的选择,可能会或可能不会给出更好的结果,是欺骗一些并且硬连线尺寸以匹配文本大小,例如“24sp”而不是“wrap_content”作为高度。
Try
android:includeFontPadding="false"
to see if it helps. It will help a little bit, but there's no way of reducing the TextView dimensions to the exact pixel-perfect text size.The only alternative, which may or may not give better results, is to cheat a bit and hard-wire the dimensions to match the text size, e.g. "24sp" instead of "wrap_content" for the height.
相关问答
更多-
ColumnLayout中文本元素上方和下方的空白区域(Empty space above and below Text elements in a ColumnLayout)[2023-08-10]
我也遇到过这个问题,而且没有解决方案。 但是,在Qt 5.4中,添加了FontMetrics和TextMetrics QML类型。 TextMetrics FontMetrics有一个全面的API,它反映了C ++ QFontMetricsF类,其中一些是命令式(函数)。 TextMetrics接受FontMetrics中的函数,并为方便起见使它们具有声明性(属性),以及一些额外的完整性属性。 给定一些文本字符串,TextMetrics将为您提供tightBoundingRect属性,顾名思义,该属性是字符 ... -
徽标通常设置为CSS背景。 然后,您可以使用边距和填充的组合来对齐包含背景的元素内的文本。Welcome to XYZCSS: .title { background-image:url(...); background-repeat:no-repeat; height:60px; padding-left:50px; <-- move the text to the right of the logo ...
-
在评论讨论后,我提出使用::selection { background: none; } ::selection { background: none; }混合OP使用position: relative在这个特定的上下文中解决了这个问题: @import url(http://fonts.googleapis.com/css?family=Roboto:300,400,500,700); span { font-size: 50px; font-weight: 600; font-f ...
-
您可以通过将文本元素放置在单元格中,将它们设置为position: absolute; 并使用transform: translate(50%, 0);将它们的50%自己的宽度推出单元格transform: translate(50%, 0); 。 当然,您需要正确的供应商前缀才能支持旧版浏览器。 .Row { display: table; width: 100%; table-layout: fixed; border-spacing: 10px; } .Column { ...
-
链接文本上方的空白空间(Empty space above link text)[2023-11-18]
我发现你没有关闭ui标签内的div标签。 我在这里更新小提琴https://fiddle.jshell.net/7v7m5uuj/ 你可以检查它是否看起来像这样。 I found you haven't close the div tags inside the ui tags. I update a fiddle here https://fiddle.jshell.net/7v7m5uuj/ You may check if it looks like this. -
在SideBar上方添加空间(Add Space Above SideBar)[2023-02-13]
给段号标题赋予高度,它会在第一行上方添加空格。 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 40; //set this value } give height to your section header it will add space above first row.. - (CGFloat)tableView:(UITableView ... -
给DIV上方和下方的空间(give space above and below a DIV)[2022-08-01]
您使用CSS padding属性 。 在你的情况下,你可能想单独使用padding-top和padding-bottom 。 语法如下: padding: top right bottom left; 要么 padding: vertical horizontal; 一些例子: // This will set the top space to 1px, the right to 2px the bottom to 3px // and the left to 4px .input { padd ... -
正如你设置了android:layout_width="match_parent" , TextView占用了所有的宽度,所以你设置的drawablePadding将不起作用。 所以你需要设置android:layout_width="wrap_content" 。 尝试下面的代码:
文字上方和下方的空间(Space above and below text)[2022-12-29]
尝试使用android:includeFontPadding="false"来查看是否有帮助。 它会有所帮助,但是没有办法将TextView尺寸缩小到完全像素完美的文本尺寸。 唯一的选择,可能会或可能不会给出更好的结果,是欺骗一些并且硬连线尺寸以匹配文本大小,例如“24sp”而不是“wrap_content”作为高度。 Try android:includeFontPadding="false" to see if it helps. It will help a little bit, but there ...CSS代码到文本上方的边距空间只影响背景?(CSS code to margin space above text Only without effecting the background?)[2022-10-15]
您正在寻找的只是'填充'。 .myClass { padding-top:10px padding-bottom:10px; } What you're looking for simply 'padding'. .myClass { padding-top:10px padding-bottom:10px; }相关文章
更多- Python字符串格式化
- 字符串应用之字符串编码转换
- redis 字符串(String) SET 操作
- Java 中String , StringBuffer 和StringBuilder
- C#--浮点数取小数点后两位和保存两位(转载)
- Java String类
- Python 字符串操作
- java数字格式化类DecimalFormat详解
- 遍历字符串每个字符,Stringreader是不是要比string.toCharArray来的快?
- Lua 字符串操作
最新问答
更多- sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
- 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
- AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
- Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
- 湖北京山哪里有修平板计算机的
- SimplePie问题(SimplePie Problem)
- 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
- HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
- 为什么我会收到链接错误?(Why do I get a linker error?)
- 如何正确定义析构函数(How to properly define destructor)
- 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
- 类型不匹配 - JavaScript(Type mismatch - JavaScript)
- 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
- 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
- 如何开启mysql计划事件
- 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
- 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
- java日历格式(java Calendar format)
- Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
- 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
- LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
- 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
- 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
- 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
- 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
- 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
- Assimp详细说明typedef(Assimp elaborated type refers to typedef)
- 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
- 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
- Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)