I want to round a number, which is
0.047518320381641387939453125(now) ----> 0.05(expected)
but I used the following function,
only got the result
.00
Could anyone give me a hand?
You can try this:
${#numbers.formatDecimal(content.number == null ? 0 : content.number, 0, 0)}
This is working for me.
Obviously the data type of data.userdSpace is the Integer.
If you change Integer to Double, it will work.
Related
I am a quite beginner in Maxima.
I am wondering if I can do the following:
I want to get a partial differential of a function like:
depends(w_r,[r]);
depends(w_theta,[theta]);
depends(e_r,[r]);
depends(e_theta,[theta]);
f(r,theta):=diff(w_r*e_r+w_theta*e_theta,r,1);
f(r,theta) includes the term de_r /dr, but I know de_r/dr = 0.
Is there a way to tell to Maxima that de_r/dr = 0 ?
Thanks
Sorry, but subst(diff(e_r,r,1)=0) looks working.
I don't know how to find keyword for this (*-) in Google, and I don't know what is name. So I ask here.
Sample code :
StartDate:=IncMinute(FinishDate,TotalMinutes*-1);
What is TotalMinutes*-1 if I write in 'normal' syntax ?
It is multiplying TotalMinutes by -1... IOW, it looks like it is decrementing the Minutes.
Write it like this: TotalMinute * -1 and it is more clear. The * is the multiplication operator and the - is the unary minus operator.
I have such code in controller's method for rounding (only higher) and display ceil part of number:
#constr_num.each do |cn|
non_original_temp_var2 = get_non_tecdoc_analogs(cn.ARL_SEARCH_NUMBER, #article.supplier.SUP_BRAND, false)
non_original << non_original_temp_var2
end
#non_original = non_original.flatten!
#non_original.each do |n_original|
n_original.price = my_round2(n_original.price * markup_for_user)
end
def my_round2 a
res = (a / 1.0).ceil * 1
res
end
But for some reasons i see with every price comma with 0 after it, for example: 5142.0 but it must be 5142
Main strange part is that, if i try to write:
n_original.price = 123
in view i see 123.0
What happend?
Only when i write in view (when displaying price):
price.ceil
i see normal numbers, without comma
What i di wrong? How to ceil my numbers with rounding (but only high, for example 2.24 is 3 3.51 is 4 and 2.0 is 2)? Becouse now for some reasons i see comma and nul after my number, even if i try to "hardcode" number in controller.
How about using the next or succ function of the Integer class? Try something like the following:
def my_round2 a
(a.is_a? Integer) ? a : a.to_i.next
end
If a is an Integer then return a otherwise cast it to Integer using the to_i method and call next or succ method on it.
Reference: http://www.ruby-doc.org/core-2.0/Integer.html
I guess I missed the second part of your question. To avoid the decimal places I guess you would have to use the a.to_i like Philip Hallstrom has suggested.
My guess is that your price field is a Float. Floats will be printed with a decimal spot by default. You need to either cast it to an Integer earlier on (say in my_round2 method) or in your view task a .to_i onto the output.
I got problem in grails, when i want to create some Code for Transfer Transaction.
def beforeInsert(){
Integer count= Transfer.count()+1
Integer width= transactionMaster.width
String c = sprintf('%05d',count)
number = transactionMaster.code+"/"+c
}
the code above especially in variable number, will give result like this : 00007.
Now the problem is, how to make '%05' change according to variable width??
For example if the width is 5, then the number will give result: 00007
if the width is 2, then the number will give result: 07
if the width is 10, then the number will give result: 0000000007
hope someone can help and if you have any solutions, can you mail me to : medmodest#gmail.com
i rarely open this website, thanks :)
This is more a groovy question, you can use groovy GString.
Instead of:
...
String c = sprintf('%05d',count)
...
Use this:
...
String c = sprintf("%0${width}d",count)
...
Hope this helps
Easy question here, probably, but searching did not find a similar question.
The # operator finds the length of a string, among other things, great. But with Lua being dynamically typed, thus no conversion operators, how does one type a number as a string in order to determine its length?
For example suppose I want to print the factorials from 1 to 9 in a formatted table.
i,F = 1,1
while i<10 do
print(i.."! == "..string.rep("0",10-#F)..F)
i=i+1
F=F*i
end
error: attempt to get length of global 'F' (a number value)
why not use tostring(F) to convert F to a string?
Alternatively,
length = math.floor(math.log10(number)+1)
Careful though, this will only work where n > 0!
There are probably a dozen ways to do this. The easy way is to use tostring as Dan mentions. You could also concatenate an empty string, e.g. F_str=""..F to get F_str as a string representation. But since you are trying to output a formatted string, use the string.format method to do all the hard work for you:
i,F = 1,1
while i<10 do
print(string.format("%01d! == %010d", i, F))
i=i+1
F=F*i
end
Isn't while tostring(F).len < 10 do useful?