number-formatting

Cross Platform Support for sprintf's Format '-Flag

こ雲淡風輕ζ 提交于 2019-12-04 05:03:00
问题 The Single UNIX Specification Version 2 specifies the sprintf 's format ' -flag behavior as: The integer portion of the result of a decimal conversion ( %i , %d , %u , %f , %g or %G ) will be formatted with thousands' grouping characters [1] I can't find the format ' -flag in the c or the c++ specifications. g++ even warns: ISO C++11 does not support the ' printf flag The flag is not recognized to even warn about in Visual C; printf("%'d", foo) outputs: 'd I'd like to be able to write C

Convert decimal separator from ',' (comma) to '.' (dot) e.g. “7,5” to “7.5”

女生的网名这么多〃 提交于 2019-12-04 05:01:54
问题 Yes. I know. Those are localization settings... But I wont tell my client to change localization settings for just my app. So how to convert those numbers? Or how to change number formatting for given range. (Need dots there, user may input comas or dots, or even numbers where commas just separate like 1,000,000.00 ...) EDIT: Circumvented whole issue by CStr(), and passing on the strings. 回答1: If this is purely for display purposes then you can use custom format strings on the cells. Then

Python atof with local input

社会主义新天地 提交于 2019-12-04 04:50:58
问题 Say, I have a (German) expression which reads 10.401,40 (in Mio EUR) , I'd like to convert this to a real float (in this case around 10 billions) in Python. This is what I have thus far: import re, locale from locale import * locale.setlocale(locale.LC_ALL, 'de_DE') string = "10.401,40 (in Mio EUR)" m = re.search(r'([\d.,]+)', string) if m is not None: number = atof(m.group(1)) * 10**6 However, it raises a ValueError ( ValueError: invalid literal for float(): 10.401.40 ). Why? Isn't the

In Java, why does the decimal separator follow the Locale's language, not its country, and, more importantly, how does one override it?

*爱你&永不变心* 提交于 2019-12-04 03:57:47
I'm working on an international project and have observed that, in Java, the choice of the decimal separator is based on the Locale's language, not its country. For example: DecimalFormat currencyFormatter = (DecimalFormat) NumberFormat.getInstance(new Locale("it","IT")); System.out.println(currencyFormatter.format(-123456.78)); currencyFormatter = (DecimalFormat) NumberFormat.getInstance(new Locale("en","IT")); System.out.println(currencyFormatter.format(-123456.78)); produces the following output: -123.456,78 -123,456.78 I would have expected it to follow the country, since if I'm in the

PHP, Format Number to have always have 2 decimal places

空扰寡人 提交于 2019-12-04 03:24:23
问题 In PHP I have decimal numbers that may or may not have trailing zeros. For example 1 1.1 43.87 How do I make sure that all these numbers have exactly two decimal places like this: 1.00 1.10 43.87 回答1: You should use number_format(): number_format(1.1, 2); 来源: https://stackoverflow.com/questions/18898638/php-format-number-to-have-always-have-2-decimal-places

Format Y axis values, original figures in millions, only want to show first three digits

空扰寡人 提交于 2019-12-04 03:01:47
问题 Data for my Y axis (each country) has figures in millions: { date: "1960", germany: "72542990", spain: "30327000", france: "46621166", italy: "50025500" } How do I write the .tickFormat(d3.format("")); on my Y axis variable to format the tick values so they show up in the Y axis scale like this: 0, 20 million, 40 million, 60 million, 80 million Currently they show up as 0, 20000000, 40000000, 60000000,80000000 Thanks. 回答1: Declare Formatter formatValue = d3.format(".2s"); Use inside

What is the easiest way to pad a string with 0 to the left?

岁酱吖の 提交于 2019-12-03 23:40:10
What is the easiest way to pad a string with 0 to the left so that "110" = "00000110" "11110000" = "11110000" I have tried to use the format! macro but it only pads to the right with space: format!("{:08}", string); Shepmaster The fmt module documentation describes all the formatting options: Fill / Alignment The fill character is provided normally in conjunction with the width parameter. This indicates that if the value being formatted is smaller than width some extra characters will be printed around it. The extra characters are specified by fill , and the alignment can be one of the

Why does .NET decimal.ToString(string) round away from zero, apparently inconsistent with the language spec?

拜拜、爱过 提交于 2019-12-03 22:43:11
I see that, in C#, rounding a decimal , by default, uses MidpointRounding.ToEven . This is expected, and is what the C# spec dictates. However, given the following: A decimal dVal A format string sFmt that, when passed in to dVal.ToString(sFmt) , will result in a string containing a rounded version of dVal ...it is apparent that decimal.ToString(string) returns a value rounded using MidpointRounding.AwayFromZero . This would appear to be a direct contradiction of the C# spec. My question is this: is there a good reason this is the case? Or is this just an inconsistency in the language? Below,

How do you set percentage in Google Visualization Chart API?

扶醉桌前 提交于 2019-12-03 22:23:39
How do you set the vertical axis to display percent such as 25%, 50%, 75%, 100%? jroi_web var options = { title: 'Chart Title', vAxis: { minValue: 0, maxValue: 100, format: '#\'%\'' } }; Try escaping the % sign. I've used this to just append the % sign in the y axis. chart.draw(data, {vAxis: {format:'#%'} } ); To get comma for thousands, use {format:'#,###%'} . See http://code.google.com/apis/chart/interactive/docs/gallery/linechart.html Using bar charts, I found my results haphazard and I got to consistency by doing the following: 1. In your data column, set a value of 100, even if you add a

How to get the same value as the user is seeing from a JFormattedTextField?

天大地大妈咪最大 提交于 2019-12-03 21:38:13
问题 I'm using a NumberFormatter and JFormattedTextField , but the .getValue() doesn't return the same value as the user is seeing. I think the input-string is parsed using NumberFormats parse-method, and I get the Numberformat from NumberFormat.getNumberInstance(); with the actual Locale. So I don't think I easily can extend it and write my own parse-method? In example , if the user types 1234.487 the getValue() will return: 1234.487 but the user will be displayed 1,234.49 Another example , using