I have value 6666666666666666.6 and using fmt:formatNumber to format on jsp(jstl)
<fmt:formatNumber type="NUMBER"
minFractionDigits="2"
maxFractionDigits="2"
value="6666666666666666.6"/>
Display result: 6,666,666,666,666,667.00
Result expect: 6,666,666,666,666,666.60
Please share me a solution.
Thanks
Have you tried changing the type from number into currency?
<fmt:formatNumber type="CURRENCY"
minFractionDigits="2"
maxFractionDigits="2"
value="6666666666666666.6"/>
<c:set var="N-15-digits" value=${666,666,666,666,666.6}/>
<c:set var="N-16-digits" value=${6,666,666,666,666,666.6}/>
<fmt:formatNumber value="${N-(0.1-(N%0.1))%0.1}" type="number" minFractionDigits="2"/>
This solution could always show without rounding If input value under 16 digit, result comparison is on following.
N-15-digits would show
666,666,666,666,666.60
N-16-digits would show
6,666,666,666,666,667.00
Related
I want to apply validation if -ve value is entered. I could do that using below tags and attributes:
<h:inputText id="MyPrice" validatorMessage="negatieve prijs niet toegestaan">
<f:convertNumber type="number"
groupingUsed="true"
locale="nl_NL"
maxFractionDigits="2"
minFractionDigits="2"/>
<f:validateLongRange minimum="0"/>
<h:inputText>
<rich:message for="MyPrice"/>
Using this I can successfully validate -ve and +ve values with below inputs:
Went right for: [I'm following Netherlands number system where ',' is treated as '.' eg to write 0.55 we need to write 0,55) that is done by me using <f:convertNumber>.
100
10.25
10,98
-100
-10.25
-10,98
0.55
But when I entered -0,55, validation didn't work. Kindly provide solution to validate when I'm entering -ve value that starts with -0.xx.
Your validator is not correct - price is not Long. Change it to
<f:validateDoubleRange minimum="0" />
I have used pattern I want to price equal 30 or Greater BUT not less.
Look my html code -
<input type="text" required="required" pattern="29+\.[0-9]*[1-9][0-9]*$" data-error="#Please enter price equal 30 or more" placeholder="Price" id="price" class="form-control" autocomplete="off" name="price" />
<div class="help-block with-errors"></div>
Above co I have used pattern="29+\.[0-9]*[1-9][0-9]*$" but this pattern not working. I have tried in different expression like 29*\.[0-9]*[1-9][0-9]*$, ^\d{30,}$, ^[0-9]\{30,}\$ these expressions also not working.
I am using bootstrap validator. Link = http://1000hz.github.io/bootstrap-validator/#validator-examples
Please help me.
*Edit : *
Now I am using ^[3-9]+\d*$ this is working fine. But it takes 3 or more than 3. I need 30 or more
You really should not be using regexes for this kind of task. But if you do want to, try this:
([3-9][0-9]|[0-9]{3,})
I have this value
<c:set var="string1" value="SS4444"/>
What I am try to achieve is to get the numbers only (4444) from the above variable. I can use substring, but the index value might change, ie it can be 'SS4444', 'S4444', 'SSS444', so cant rely on static index.
Thanks in advance
Split it with regex.. (substringAfter is not proper for this..):
<c:forEach var="string1" items="${fn:split(yourstring, '^\w*')}">
<c:set var="string2" value="${string1}"/>
</c:forEach>
You can try with replace function as:
<c:set var="strng" value="SS4444"/>
<c:set var="strng1" value="${fn:replace(strng,'S','')}"/>
i have two arrays (strings delimited with commas) and i made a foreach loop on one of this vars
i need to be able to access to the other string with the foreach index like
<c:set var="name" value="Zara,nuha,roshy" />
<c:set var="name2" value="Zara2,nuha2,roshy2" />
<c:forEach items="${name}" delims="," var="name" varstatus="i">
<c:out value="${name}"/><br>
</c:forEach>
i need to access name2 values, in the name foreach, is it possible without doing another foeach?
The varstatus variable you are using contains a value "index" that you can use.
But, you can't operate on a string like that (not that I know of at least).
First, you need to convert name2 to a proper array or list. Then you can access it inside the for loop:
${name2list[i.index]}
Now, how to convert it to an array? How about the split function?
<%#taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="name2list" value="${fn:split(name2, ',')}"/>
This can be done, contrary to some previous comments.
See the following example based on the question:
<c:set var="names" value="Zara,nuha,roshy" />
<c:set var="names2" value="Zara2,nuha2,roshy2" />
<c:forEach items="${names.split(',')}" varStatus="i" var="name" >
${name} : ${names2.split(',')[i.index]}<br/>
</c:forEach>
Essentially we're using a string split function with expression language to get a string array from list comma separated values. Within the loop we the get the second value from the names2 array by using the varStatus index. I believe this accomplishes the task.
I am new to Dojo programming and trying to create a ValidationTextBox for username input. I would like to have three criteria: 1. users can only input alphanumeric characters and 2. minimum length of a username is 6 character 3. this field is required
So far my input looks like:
<input name="username"
type="text"
id="username"
class="reqd1"
required="true"
trim="true"
lowercase="true"
promptMessage="Username"
invalidMessage="Please only enter alphanumeric characters."
maxlength="12"
regExp="[\w]+"
intermediateChanges="false"
dojoType="dijit.form.ValidationTextBox" />
I have three questions:
1. how I can check for the the minimum character of the username field?
2. Is there a way to change the invalidMessage programatically?
3. How I can check the length of the username field without using regEx?
regExp="\w{6,12}"
dijit.byId("username").set("invalidMessage", "new message");
I think regExp is the best way in your case