Android Question Hebrew Currency with Number String

Discussion in 'Android Questions' started by EvgenyB4A, Jul 13, 2019.

  1. EvgenyB4A

    EvgenyB4A Active Member Licensed User

    I need to output the string like שח 10.00 where שח will be at the start and then 10.00. I can't succeed in anyway.
     
  2. emexes

    emexes Well-Known Member Licensed User

    Code:
    Dim IOU As Double = 10.15    'money values better as Double (Float is only 6 digits accurate)
    Dim MoneyString As String = "שח " & NumberFormat2(IOU, 122False)
    Log("How about " & MoneyString & " ?")

    IOU = IOU * 
    2
    MoneyString = 
    Chr(8362) & " " & NumberFormat2(IOU, 122False)
    Log("Or do you prefer " & MoneyString & " ??")
     
    Last edited: Jul 13, 2019
    Shelby likes this.
  3. EvgenyB4A

    EvgenyB4A Active Member Licensed User

    Anyway I get the following: "How about שח 10.15 ?" I need that שח will be the first and then 10.15
     
  4. emexes

    emexes Well-Known Member Licensed User

    Yeah, I just tested the second sample Chr(8362) and noticed that the first sample was still the wrong way around. That's interesting. I remember with Arabic writing in Windows, text used to move itself about when changing direction, perhaps the same is happening here when the text output routine sees your currency symbol.

    update: the B4A IDE cursor does very strange things when traversing those characters too...
     
  5. EvgenyB4A

    EvgenyB4A Active Member Licensed User

    It is not because of currency symbol. If English part of string will be like "abcd" al will loos OK : " שח abcd" .
     
  6. emexes

    emexes Well-Known Member Licensed User

    According to this page:

    https://www.fileformat.info/info/unicode/char/5E9/index.htm

    the first character is right-to-left, and I expect the other character will be too. So now I am looking at how to override text directionality. Or to trick it somehow into putting the symbol first.

    A workaround might be to put the currency symbol in one label, and the monetary number in a separate label.
     
  7. emexes

    emexes Well-Known Member Licensed User

  8. Mahares

    Mahares Well Known Member Licensed User

    Code:
    Dim IOU As Double = 10.15   
        
    Dim s As String=NumberFormat2(IOU, 122False)
        
    Log($"nw ${s}"$)    'displays: nw 10.15
     
  9. emexes

    emexes Well-Known Member Licensed User

    I am going to have to admit defeat on this one, for tonight at least.

    If you place text between the currency characters, then they stay in left-to-right order. So I figure if I could just find some non-printing characters to put between the currency characters, that would do the job (although no doubt I'd cop an ear-bashing from Erel ;-)

    However, that doesn't work. Java's handling of text direction is irritatingly thorough.

    I tried CSBuilder too, thinking that the formatting codes in that might interrupt the text direction handling, but... no luck there either.
     
  10. emexes

    emexes Well-Known Member Licensed User

    This post made me think of another workaround: use the ISO currency code "ILS"
     
  11. emexes

    emexes Well-Known Member Licensed User

    Or apparently CSBuilder can include images within a string, so... you could include an IMAGE of the two currency characters... bit of an icky solution, but hey: if it works, it works ;-)
     
  12. Mahares

    Mahares Well Known Member Licensed User

    Use string literals, you will get it:
    Code:
    Dim IOU As Double = 10.15  
        
    Log($"nw ${NumberFormat2(IOU, 122False)}"$)  'displays: nw 10.15
     
  13. EvgenyB4A

    EvgenyB4A Active Member Licensed User

    nw will be looked apparently. I used literals string but it doesn't help.
     
  14. emexes

    emexes Well-Known Member Licensed User

    Give this a burl:
    Code:
    Dim IOU As Double = 10.15    'money values better as Double (Float is only 6 digits accurate)
    Dim MoneyString As String = Chr(0x200F) & NumberFormat2(IOU, 122False) & " " & Chr(1513) & Chr(1495)
    Log("How about " & MoneyString & " ?")

    IOU = IOU * 
    2
    MoneyString = 
    Chr(8362) & " " & NumberFormat2(IOU, 122False)
    Log("Or do you prefer " & MoneyString & " ??")
     
    Last edited: Jul 13, 2019
    Erel and EvgenyB4A like this.
  15. EvgenyB4A

    EvgenyB4A Active Member Licensed User

    Thank you very much. It works.
    Chr(0x200F) makes a job.
     
    emexes likes this.
  16. emexes

    emexes Well-Known Member Licensed User

    I wish I could explain why it works, except that I'm a bit hazy about it myself.

    Likewise, I wish I could say that I derived the solution by skill and wisdom, but in fact it was more by perseverance and luck.

    I googled Unicode left right direction and eventually I found pages like http://unicode.org/reports/tr9/#Explicit_Directional_Embeddings

    and from there I tried using various directional formatting characters and sequences until I found one that worked with both Log() and with Label.Text =
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice