format number to currency haml - haml

I am working on a code written in haml, for converting number to currency developer has coded like following.
to_currency payment.amount
It is converting number 5 as $5.00, but this is a credit amount so I need to display it as ($5.00) instead of $5.00.
Any recommendations what should I change in to_currency?

I don't know that this is really a HAML question, since you're asking what to change in your to_currency function, which is surely held in a controller or helper file, not a HAML file. However, you can interpolate the function into any HAML file like this:
You save (#{to_currency(payment.amount)})
If to_currency were to return $5.00, the above HAML line would produce:
You save ($5.00)
Depending on your code, this might be the better method, anyway. That way, you can leave your original to_currency function alone, which may be providing results to other portions of the app which expect the results with no parentheses.

Related

SAP Smartforms layout trouble with packed numbers

I'm currently trying to fill a smartform with some information. I have a simple text element and read the data fields via &name&. The data itself gets read perfectly fine, however the layout is incorrect. Some fields are just plain text, and others are defined as packed numbers with 2 decimals. These packed number fields for some reason are out of alignment, always showing one line below everything else that is supposed to be in this line. That looks like that:
How can I get the 121,08 in this example on the same height as the rest? The text element looks like the following:
test &field1& &field2& &field3&
Only field 2 is a packed number, therefore I think it might have something to do with that.
Use as below. C will remove extra space.
&field2(C)& &field2(C)& &field3(C)&

OpenOffice Calc numeric formatting language

I am trying to display always-signed integers ('-1', '+4', etc: I'll even accept '+0') in OpenOffice Calc. I've had trouble finding exact information on the numeric formatting language used.
=TEXT(cellref;"#0")
doesn't display '+', and using "+#0" always displays '+' (it displays '-+3' for -3 in fact.)
Is there a format code for this, or do I have to write a function to handle the cases?
Here is a short but cryptic solution:
=TEXT(cellref;"\+#;\-#;0")
This is actually a three-part format code. It adds either a plus sign \+# for positive numbers, a minus sign \-# for negative numbers, or just a plain 0 for zeroes.
The syntax is described here: https://help.libreoffice.org/5.2/Common/Number_Format_Codes#Positive_and_Negative_Numbers
Another approach is to apply custom formatting, which is generally a good idea where numbers are involved, to make calculations with them easier:
"+"#;"-"#;0;General

wxStaticText inconsistently displays 'degree' character

In the same application I have two different instances of wxStaticText. Each displays an angular value expressed in degrees. I've tested both instances for font name and font encoding. They are the same for both. I've tested that both strings passed to SetLabel() are using the same character value, decimal 176. Yet one displays the 'degree' character (small circle, up high) as expected and the other instead displays an odd character I'm not familiar with. How can this be? Is there some other property of wxStaticText I need to test?
I can't explain what you're seeing because obviously two identical controls must behave in the same way, but I can tell you that using decimal 176 is not a good way to encode the degree sign, unless you explicitly use wxConvISO8859_1 to create the corresponding wxString.
It is better to use wxString::FromUTF8("\xc2\xb0") instead or, preferably, make sure that your source files are UTF-8 encoded and just use wxString::FromUTF8("°").
Arghhhh! Found it. I was assuming SetLabel() was wxStaticText::SetLabel(), inherited from the wxWindow base class. It's not. We have a wrapper class of our own around wxStaticText that I was not aware of. It's the wrapper class that is bollixing the string value.
Moral: When debugging unfamiliar code, don't make assumptions, step ALL THE WAY in.

SQL Strip the Font Format(Colour or other)

I have a problem to strip out the format in a note table
Here is an example:
";\red31\green73\blue125;
\viewkind4\uc1\ltrpar\f0\fs20 USEFUL TEXT BODY \cf1\f3
\ltrpar\f0\fs17
"
How to get rid of those stuff? I want to play safe not to replace anything after'\'
Many thanks,
Rick
Your making it quite difficult for yourself by not replace '\' .
If you look at http://other9.tripod.com/Refs/easy-rtf.html you will see that there are different RTF codes and there is no default size for the codes.
Additionally, it is not like HTML where there must be a necessary "closing" tag which makes it additionally difficult.
The only thing I can think of is to record all possible RTF codes (or use an RTF parser library) and hence be able to recognize if a \ is or is not RTF code.

date object prefixing with # vb.net

I am writing sample code for Date conversion using VB.net.
Problem i am facing that it is prefixing and suffixing with hash(#) symbol.
ex : #2010-12-12#.
How to remove # symbol so that i can only date.
Given your comment, it sounds like this is actually probably just an issue of displaying a DateTime in the debugger. It showing you the DateTime literal form that you could use in VB. This is a bit like C# developers who are concerned about their strings having double backslashes in, when actually that's just the debugger showing escaping.
The DateTime itself doesn't really contain the hashes, and none of the normal format strings will produce hashes either. If you want to see it without the hashes, add a watch for
arrTxLifeReq(0).TransExeDate.ToString()
Does the code which is part of your real program have any problems? If so, please post details of those problems rather than just what the debugger is showing.
Just replace # with ''
for example
string dt = "#2010-12-12#";
dt = dt.Replace ("#","");