String Format Integer With Commas, No Decimal Places and Nothing for 0 Values - wpf

Okay before I get right into my question does anyone know if there is a tool for building string formats? What I'm thinking is something like a pretty simple user interface where you choose whether you want to display commas, zero values, dollar signs etc and then it spits out the stringformat for you. If there is one I'd love to know about it. If there's not it's the sort of thing people like me would love!
My question is. What is the string format for displaying an integer with comma separators for thousands, no decimal places and nothing for zero values.
I know the string format for an integer with comma separators and no decimal places is:
StringFormat='0,0.'
And I know the string format for displaying nothing for zero values is:
StringFormat='{}{0:#}'
But combining the two has me stumped. Thanks very much!

I'm not 100% sure what you're after, but after comparing your two string formats, I think I know what you're after... please let me know if I am mistaken.
Once again, you almost had what I think you want... how about trying this:
StringFormat='{}{0:#,#.}'
Or just
StringFormat='#,#.' (Just replace the '0' from your example with '#')
These are equivalent. Please note that again, these will both round the number to the nearest integer.
UPDATE >>>
Here are two very useful links to help you with your string.Formats in the future:
Custom Numeric Format Strings
Custom Date and Time Format Strings

ContentStringFormat is separate dependency property out side of Bindig{} assets.
ContentStringFormat='{}{0:#}'
Example:
<Label Content="{Binding Path=MaxLevelofInvestment}" ContentStringFormat="Amount is {0}" />

Related

Use disabled input to display data

To get a consistent look and feel of both input and output views I am trying to use an disabled input element to display model data/values.
The value is a calculated temperature value and has several decimal digits. Since that does not make sense from an engineer's point of view I want to limit the displayed decimal digits to a certain amount (let's say two digits, the displayed value does not need to be rounded).
Example:
calculated value: 123.123456
value to display: 123.12
I read around the Internet and found many suggestions using input's step attribute like
step=".01"
to limit the decimal digits. There seem to be many people doing it that way, but it does not work for me.
I think view and data model need to kept separated so adapting the model data (like converting the values to strings or using toFixed()) does not seem to be a nice solution. The view should be able to format the data itself, not changing the data model and should have reading access in this case only.
There is a filter for doing this when accessing model data through the {{ }} notation. But this does not seem to be applicable straight out of the way.
So, do you have any suggestions about limiting the decimal numbers?
For the sake of investigation and in order to provide a working sample code I created a Pen.

How do I make XamCurrencyEditor accept either parentheses or a minus sign?

<XamCurrencyEditor FormatProvider="{Binding Path=CurrencyFormat.CurrencyFormatInfo}"
Mask="{Binding Path=CalculatedMask}" />
CurrencyFormat.CurrencyFormatInfo is a NumberFormatInfo calculated from our currency format business object. CalculatedMask is set to "{currency:-22.2:c}", which allows positive or negative currencies with up to 22 digits before the decimal and 2 after.
I would like the editor to allow either parenthesis or a minus sign for negative values:
$ -123.45
($ 123.45)
CurrencyNegativePattern is already set to 0. I tried changing the Mask to "{currency:(22.2):c}", but that is just inserted as a literal string. Will I have to generate a custom format string to get the desired behavior?
As a partial solution, adding Format="C" causes the editor to fully respect the FormatProvider when formatting its value.
<XamCurrencyEditor FormatProvider="{Binding Path=CurrencyFormat.CurrencyFormatInfo}"
Mask="{Binding Path=CalculatedMask}"
Format="C" />
The editor still refuses to accept parentheses. If anyone from Infragistics is reading, please consider this a feature request.

Decimal as first character in a number input field

I have a <input type="number"></input> field and when I try to put in a decimal as the first character, it comes up as invalid (I have an ng-change firing).
.5 won't work, but 0.5 is valid. Is there something I can do about this?
Per the HTML spec, .5 is valid for <input type="number">.
So, you’re right, and the tool (browser? Angular?) that validation error’s originating from is wrong.
As far as how to deal with it—how to work around it—I don’t know what to suggest, but as someone who actually works on the specs for this stuff, I would like to ask you to please at least file a bug against whatever tool is (mis)performing the actual validation that’s causing you to see that message. If nobody takes time to report spec-conformance bugs like this (but instead everybody works around it by just putting, e.g., 0.5 to get past it), then the bugs never get fixed.
Anyway as far as evidence for my assertion that .5 is in fact valid: The HTML spec is pretty clear on this; see the section defining what a valid floating-point number is:
A string is a valid floating-point number if it consists of:
Optionally, a U+002D HYPHEN-MINUS character (-).
One or both of the following, in the given order:
A series of one or more ASCII digits.
Both of the following, in the given order:
A single U+002E FULL STOP character (.).
A series of one or more ASCII digits.
Optionally:
Either a U+0065 LATIN SMALL LETTER E character (e) or a U+0045 LATIN CAPITAL LETTER E character (E).
Optionally, a U+002D HYPHEN-MINUS character (-) or U+002B PLUS SIGN character (+).
A series of one or more ASCII digits.
Along with that evidence from the spec itself, here’s a record of other supporting evidence: There was in fact a time when the HTML spec didn’t allow .5 but instead required it to be written as 0.5; however, after a “Floating point numbers beginning with a dot should be valid and parsed correctly” bug was raised against the spec, the spec was subsequently changed (in 2011) to state what it currently states (that is, too allow, e.g., .5).
So, any tool that’s flagging .5 as an error likely has not been updated in this regard since 2011, and so it regardless is in need of its maintainer(s) to go back into their code & evaluate their code against the current spec requirements, to make sure they are conforming to the current spec.
I hope the above provides enough ammunition to use in raising a bug against the responsible tool.
If you want all the input numbers to be valid then you can set in your input field step to "any". It works all integers and decimals numbers. Like -
<input type="number" step="any" />

Validation rules in access

I recently started learning and using microsoft access. However, I am afraid that there is something really bothering me. It's connected with the validation rules. So here is my problem:
I had to validate a field so that only letters could be written. Of course I googled it and found the proper syntax. (Is Null or Not Like "*[!a-z]*")
At first I tried with (Is Null or Like "*[a-z]*"), which I think should be the same as the above one. It's checking every symbol from the string whether it is between 'a'and 'z' and that is why it is used with the obelisk * symbols from the both sides. Am I right?
My question is: Why is the second one not working, although it is a double negative equivalent to the first one. Will be happy for any explanation. Thanks in advance!
P.S Sorry if the question seems useless for you but I really do want to figure out where I am mistaking.
Consider the string 'a1b'.
Like "*[!a-z]*" will search the string for any character that is not in the range 'a'..'z'. It finds the '1' in the second position and returns True. Therefore, Not Like "*[!a-z]*" returns False.
On the other hand, Like "*[a-z]*" searches the string for any character that is in the range 'a'..'z'. It finds the 'a' in the first position and returns True.

Unicode/special characters in help_text for Django form?

I am trying to add a special character (specifically the ndash) to a Model field's help_text. I'm using it in the Form output so I tried what seemed intuitive for the HTML:
help_text='2 – 30 characters'
Then I tried:
help_text='2 \2013 30 characters'
Still no luck. Thoughts?
django escapes all html by default. try wrapping your string in mark_safe
You almost had it on your second try. First you need to declare the string as Unicode by prefacing it with a u. Second, you wrote the codepoint wrong. It needs a preface as well; like \u.
help_text=u'2\u201330 characters'
Now it will work and has the added benefit of not polluting the string with HTML character entities. Remember that field value could be used elsewhere, not just in the Form display output. This tip is universal for using Unicode characters in Python.
Further reading:
Unicode literals in Python, which mentions other codepoint prefaces (\x and \U)
PEP263 has simple instructions for using actual raw Unicode characters in a source file.

Resources