string-formatting

Currency Culture Formatting not applying on DataGridView Column

情到浓时终转凉″ 提交于 2019-12-06 14:21:20
I have 2 DataGridViews (DGV), and in both I have currency columns which I want to format. The code I'm writing seems to work in one, but not in the other. Both the DGV's are set up this way: Data is first loaded into a DataTable. A BindingSource then links to this DataTable. And lastly the DGV's use this BindingSource object for their data. I use the following code in the form's Load event to customize both DGVs' currency columns: dataGridView.Columns[columnIndexHere].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("de-DE"); dataGridView.Columns[columnIndexHere].DefaultCellStyle

How do you format text/strings in VBA?

偶尔善良 提交于 2019-12-06 14:17:53
In the code below, I take some input parameters, either text or a cell, and combine them to form one string using the formatting I need. I need to make Task_Name bold, as well as text like "Lead :". I know you cannot make text in a variable bold, but how do I go about this? This cell I'm storing the value in is eventually used in a Word mail merge. I need to format part of a string. In the code below, I need to make Task_Name, "Lead : ", etc. all bold. Function GENERATE_STAFFING_SECTION(Task_Name, Lead_By, Members, Instructions) Dim tmpSection As String If Len(Task_Name > 0) And Len(Lead_By) >

C# format as currency with no trailing zero decimal numbers, consider negative, and different culture

我怕爱的太早我们不能终老 提交于 2019-12-06 13:50:13
问题 How can we format a number to currency without trailing zero decimal numbers? Basically it should behave as the "C" format specifier but without trailing zeroes. Below are the test cases. value | en-US | fr-FR 1 | $1 | 1 € 1.0 | $1 | 1 € 1.1 | $1.1 | 1,1 € 1.10 | $1.1 | 1,1 € -1 | ($1) | -1 € -1.0 | ($1) | -1 € -1.1 | ($1.1) | -1,1 € 1000 | $1,000 | 1 000 € 1000.0 | $1,000 | 1 000 € Is there a way to achieve this behavior by leveraging the "C" format specifier? side note: I am continuing from

No format security warnings in Xcode 4.4

爱⌒轻易说出口 提交于 2019-12-06 13:23:49
问题 I don't get any format security warnings ( -Wformat-security ) from this code using Xcode 4.4: #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { // a = @"%@" or a = @"%@%@" NSString *a = [@"%@" stringByAppendingFormat:@"%@", arc4random_uniform(2)? @"%@": @"", nil]; // 50% change of crash, but no warning NSLog(a, @"Hello, World!"); } return 0; } Is this normal or have I somehow disabled this warning in Xcode? I have just created the project with

Binding a unit label in WPF textbox

隐身守侯 提交于 2019-12-06 13:16:52
I'm binding a pressure to a textbox. The pressure could be in PSI, KPA, BARS, etc. I would like to display the unit inside the textbox next to the value. There doesn't seem to be a way to bind the Units string property in my viewmodel to the StringFormat option of the value binding. Is there any way to accomplish this without retemplating the textbox? You can use MultiBinding : <TextBox> <TextBox.Text> <MultiBinding StringFormat="{}{0} {1}"> <Binding Path="Pressure" /> <Binding Path="Unit"/> </MultiBinding> </TextBox.Text> </TextBox> 来源: https://stackoverflow.com/questions/14758318/binding-a

center a string by padding spaces up to a specified length

风流意气都作罢 提交于 2019-12-06 08:29:57
I have a vector of names, like this: x <- c("Marco", "John", "Jonathan") I need to format it so that the names get centered in 10-character strings, by adding leading and trailing spaces: > output # [1] " Marco " " John " " Jonathan " I was hoping a solution less complicated than to go with paste , rep , and counting nchar ? (maybe with sprintf but I don't know how). Here's a sprintf() solution that uses a simple helper vector f to determine the low side widths. We can then insert the widths into our format using the * character, taking the ceiling() on the right side to account for an odd

How to format a string as Vietnamese currency?

六月ゝ 毕业季﹏ 提交于 2019-12-06 07:33:51
问题 If I set Format in [Region and Language] to US... CultureInfo cul = CultureInfo.CurrentCulture; string decimalSep = cul.NumberFormat.CurrencyDecimalSeparator;//decimalSep ='.' string groupSep = cul.NumberFormat.CurrencyGroupSeparator;//groupSep=',' sFormat = string.Format("#{0}###", groupSep); string a = double.Parse(12345).ToString(sFormat); The result is: 12,345 (is correct) But if I set the format in [Region and Language] to VietNam, then the result is: 12345 The result should be 12.345 .

Capturing **vars() pattern in string formatting

假装没事ソ 提交于 2019-12-06 07:27:52
问题 I frequently find myself using the following pattern for string formatting. a = 3 b = 'foo' c = dict(mykey='myval') #prints a is 3, b is foo, mykey is myval print('a is {a}, b is {b}, mykey is {c[mykey]}'.format(**vars())) That is, I often have the values I need to print in the local namespace, represented by a call to vars(). As I look over my code, however, it seems awfully unpythonic to be constantly repeating the .format(**vars()) pattern. I'd like to create a function that will capture

Do C++ formatting libraries generally fall back to *sprintf for numeric formatting?

*爱你&永不变心* 提交于 2019-12-06 07:01:29
I am wondering whether "all" C++ formatting libraries eventually fall back to a *sprintf function to format numbers. I am asking this because: Looking at the iostreams library that comes with Visual C++, I can see that numbers input into a stream will eventuall be formatted with sprintf_s . Boost.Format just uses the available iostreams library as far as I can tell. FastFormat eventually uses vsprintf to format a number. So, are there iostreams implementations that do not use *sprintf and do the formatting themselves? Are there other formatting libraries that do not forward formatting of

AngularJS - How to apply currency filter on textbox as I type?

大憨熊 提交于 2019-12-06 05:36:47
问题 My project has a requirement to show amount field in currency format. I can achieve this onblur event, but let me know if this can be achieved using filters or some other AngularJS technique. I have the following textbox: <input type="text" class="form-control" id="MyAmount" name="MyAmount" ng-model="MyAmount" /> I want to convert the value inside this text box to follow currency format. So, if I type 200000, it should make is $200,000.00 as soon as I type or while I am typing. I used the