I try to limit input number value to 2 decimal places by using decimal pipe.
<input [ngModel]="il.unitPrice | number:'1.2-2'" [ngModelOptions]="{updateOn: 'blur'}" (ngModelChange)="updateAmount($event,i)"
class="form-control text-right" type="text" name="unitPrice{{i}}"/>
It works sometimes. But in most cases, the decimal pipe doesn't get fired.
for example, when there is no values in the input field, I type '100'. It works. The value is converted to '100.00'. If I change the input '100.00' back to '100'. I expect the value to become '100.00' again, but nothing happened.
Another case is '100.0012'. The decimal pipe doesn't get fired either.
Is there anything wrong in above codes? How to use decimal pipe correctly?
Thank you very much in advance for your help.
Related
I don't know what I am missing but I am getting the " Failed to convert parameter value from a string to a decimal" when I am trying to INSERT data.
I have a Access database with a table that has decimal fields. I am using decimal field because I need to store a number
like xx.xx.
The field is set as:
Field size as Decimal
Precision as 4
Decimal places as 2
This is the parameter I am using. I have tried many ways I have found on internet search but none work.
.Parameters.Add(New System.Data.OleDb.OleDbParameter("#RateUnitRate1", System.Data.OleDb.OleDbType.Decimal, 4, CType(tbRateUnitRate1.Text.Trim, Decimal)))
I know the textbox has a potential decimal value because when I check it with,
Dim rate As Decimal If Not Decimal.TryParse(tbRateUnitRate1.Text, rate) Then MsgBox("Not a valid input") tbRateUnitRate5.Text = "" tbRateUnitRate5.Focus() Exit Sub End If rate = CType(tbRateUnitRate5.Text.Trim, Decimal) MsgBox(rate.ToString)
I get a value of 3.50.
What am is missing.
If I have a tag like the below and the value test comes from a database and is an integer but th:text converts it to a floating point number e.g.....
<p th:text="${test}"/>
Where test....
{
"test": 5
}
the result is 5.0
However annoyingly if I use a number literal in thymeleaf e.g.
<p th:text="5+0"/>
the result is displayed correctly as 5
I know I can use something like <p th:text="${#numbers.formatDecimal(test,0,0)}"/> however this is problematic as I don't know if the value could be a number or not until runtime and so it will clutter it up with if statements etc. Would be so much better if it finds an integer to actually keep it as an integer (or convert it to a zero decimal text) - e.g. like it does with number literal. Is there any way to do this?
Many thanks for any help
To get the numbers with decimal characters in keyboard of iOS, I tried almost every trick in js and jquery (tel as input type, 0.01 as step etc...) but the only solution was the plugins:
https://github.com/mrchandoo/cordova-plugin-decimal-keyboard
https://github.com/gbrits/cordova-plugin-ios-decimal-keyboard
https://www.npmjs.com/package/cordova-plugin-decimal-keyboard-wkwebview
...
They are all working. However...
If there are more than one input fields after each other and if you switch from a "non-decimal" field to our "decimal" input field (either by arrows or by just tapping with fingers), you don't see the decimal character anymore, but just the numbers. If you unclick/click on "Done" and select the decimal input field again, it works then again.
This is the common problem of all the plugins. I'm asking myself whether it is a known issue or it is a very specific problem of my case?
This is my html:
<input v-if="isIOS" type="text" pattern="[0-9]*" decimal="true" decimal-char=","
maxlength="10" min="0" :max="detailsSelectedPunt.tMax" placeholder="Punt..." v-model="detailsSelectedPunt.Number">
<input type="text" maxlength="255" placeholder="Commentaar..." v-model="detailsSelectedPunt.Commentaar">
In an edit.gsp, where I have inputfields for decimal number, the decimal number show up as '3.123' and if I save it: I got error as the decimal point is wrong! It expect a ','. My locale is Sweden.
So I have to manually replace dot's with comma for all decimal numbers.
I've looked around the whole week and could not find a solution anywhere.
Shouldn't Grails be consistent and show commas when it expect commas in the save?
It should work with both BigDecimal and for double.
I have Grails 3.2.4
Here is an example of a "g:field" from an edit-form:
Bredd: <g:field type="number decimal" name="width" min="20" max="300" required="Y" value="${request1?.width}" style="width: 4em"/>
So, what can I do?
manually replacing dots sounds all horrible and possibly the wrong approach.
Moved answer segments around
So an update on the answer since i hit a similar issue today maybe in reverse. Sent through a number of 3333 when validation failed for another reason the number in the field had become 3,333 after the validation failure. If the old validation issue is fixed it will now fail due to comma in the number.
The reason turned out to be :
<g:textField value="${fieldValue(bean: instance, field: 'someField')}"
upon return changed number to 3,333 when changing this to
value="${instance.someField}"
Above was actual issue #larand was facing
I would store the input field width as a short
so :
Class MyClass {
//if you are storing a number like 123 (non decimal)
Short width
//if you are storing 12.12 which becomes 1212 when stored
Integer width
BigDecimal getDecimalWidth() {
return new BigDecimal(this.width).movePointRight(2).setScale(2)
}
void setWidth(BigDecimal decimal) {
this.width=new BigDecimal(decimal).movePointLeft(2).setScale(2)
}
//unsure but think this should work
Integer getWidthInteger() {
return this.width as int
}
void setWidth(Integer integer) {
this.width=(byte)integer
}
}
This will then give you methods to get the short value as big decimal using ${instance.decimalWidth} or as integer : ${instance.widthInteger}
when your field is actually numeric:
<g:formatNumber number="${myCurrencyAmount}" type="currency" currencyCode="EUR" />
To me that seems a lot more straight forward and cleaner than chopping up numbers which well you think about it
After first validation issue the number was 3333 as put in. So maybe this is your issue ? Unsure since you are talking of dots
I have an input for telephone number.
I would like to write this format: 0175 6565 6262 (with spaces). But if write with " " spaces so get error and I write without spaces so get not error.
Here my HTML Input:
<input type="text" data-parsley-minlength="6" data-parsley-minlength-message="minlength six number" data-parsley-type="digits" data-parsley-type-message="only numbers" class="input_text" value="">
Hope someone can help me?
That's a great answer, but it's a bit too narrow for my needs. Input field should be tolerant of all potential inputs – periods, hyphens, parentheses, spaces in unexpected places, plus signs for international folk – and using this document from Microsoft detailing what numbers IE11 should accept, I've come up with this:
data-parsley-pattern="^[\d\+\-\.\(\)\/\s]*$"
Every number in that list passes the test with flying colours. Enjoy!
If you want your input to accept a string like "nnnn nnnn nnnn" you should use a regular expression.
For example, you can use the following HTML:
<input type="text" name="phone" value="" data-parsley-pattern="^\d{4} \d{4} \d{4}$" />
With this pattern the input will only be valid when you have fourdigits«space»fourdigits«space»fourdigits
You can test or tweak the regular expression and test it here: http://regexpal.com/
If you will use this pattern multiple times in your project I suggest you create a custom validator (see http://parsleyjs.org/doc/index.html#psly-validators-craft)