locked
Problem with #,## RRS feed

  • Question

  • Hi!

    I have a Problem with a String:

            WPFPosABNummer = VBSATZ002.PosABNummer.Trim(" ").TrimStart("0")
    
    WPFPosABNummer is a String and PosABNummer too...

    PosABNummer = "00000,25"

    in

    WPFPosABNummer is after that line "      ,25"

    What I Need in WPFPosABNummer is "     0,25"

    Have anyone a good Idea or Hint for me how i can Format the Field right?

    Best Regards

    Bernd


    Monday, September 23, 2013 6:09 AM

Answers

  • I become only strings from any other Software and i must Format the strings correct...

    You can't adequately format a string.

    Convert those strings as supplied from that other application to numbers using (for instance) Decimal.TryParse:

    http://msdn.microsoft.com/en-us/library/9zbda557.aspx

    Use those numbers within your application as required.  When you need to convert them back to strings, use the appropriate string format method:

    http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

    Any other approach is just going to get more and more complicated as you try to handle the different conditions you will find in those strings.

    • Proposed as answer by Armin Zingler Monday, September 23, 2013 12:19 PM
    • Marked as answer by Carl Cai Friday, October 4, 2013 3:08 AM
    Monday, September 23, 2013 10:46 AM

All replies

  • Why not simply 

    CInt("00000,25").ToString("0.00")

    Be aware this assumes that the decimal separator is comma in the settings



    Success
    Cor

    Monday, September 23, 2013 6:29 AM
  • I have only strings....

    Monday, September 23, 2013 6:33 AM
  • I have only strings....

    If you can only work with strings, then you have to do it yourself.   You can test your result and if it starts with "," then insert a "0" at the beginning.  Then insert enough spaces to make it the correct length.

    If WPFPosABNummer.StartsWith(",") then WPFPosABNummer = "0" & WPFPosABNummer

    While WPFPosABNummer.length < 8
        WPFPosABNummer = "0" & WPFPosABNummer
    End WHile

    Monday, September 23, 2013 6:44 AM
  • Thats it !

    --> If WPFPosABNummer.StartsWith(",") then WPFPosABNummer = "0" & WPFPosABNummer

    What I Need :-)

    But now at last the thousend Points like that:

    "01.000,25"

    That all is fine :-)))))

    Best regards

    Bernd

    Monday, September 23, 2013 6:55 AM
  • But now at last the thousend Points like that:

    "01.000,25"

    You need to go back and consider why you are working with strings.   These values must start out as numbers - if you keep them as numbers then these sorts of problems just disappear.
    Monday, September 23, 2013 6:58 AM
  • For more Information:

    I become only strings from any other Software and i must Format the strings correct...

    in this Moment i have the Number Fileds in the right Format...

    Many Thanks for that!

    Now I Need at last the Money fields to convert right...

            WPFS1AngebotSumme = VBSATZ002.S1AngebotSumme.Trim(" ").TrimStart("0")
            If WPFS1AngebotSumme.StartsWith(",") Then WPFS1AngebotSumme = "0" & VBSATZ002.S1AngebotSumme.Trim(" ").TrimStart("0")
    

    VBSATZ002.S1AngebotSumme = "0001000,35"

    after this Code is in WPFS1AngebotSumme = "   1000,35"

    so far so good...

    Now I Need in WPFS1AngebotSumme = "   1.000,35"

    That is the last what i must convert ...

    Best Regards

    Bernd

    Monday, September 23, 2013 7:08 AM
  • I have only strings....

    Yes I used a string, be aware that "00000,25" is the same as in your code

    Dim PosABNummer as string
    PosABNummer = "00000,25"

    If I make a sample I make it as short as possible


    Success
    Cor

    Monday, September 23, 2013 7:14 AM
  • I Need now Points... "  1.000,35"...

    Best regrads

    Bernd

    Monday, September 23, 2013 7:18 AM
  • VBSATZ002.S1AngebotSumme = "0001000,35"

    after this Code is in WPFS1AngebotSumme = "   1000,35"

    so far so good...

    Now I Need in WPFS1AngebotSumme = "   1.000,35"

    That is the last what i must convert ...

     Dim AngebotSumme As String = "0001000,35"
     AngebotSumme = AngebotSumme.Replace(","".")
     Dim number As Double = CDbl(AngebotSumme)
     Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de")
     Console.WriteLine("{0:#,###.00}"number)

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    Monday, September 23, 2013 8:01 AM
  • Ist Looks like nearly good!

    The writeLine Show my the right number!

    But I Need the WrileLine Result in my Field WPFS1AngebotSumme...

    Than it is perfect !

    Best Regards

    Bernd

    Monday, September 23, 2013 8:34 AM
  •         
    DimAngebotSummeAsString = "0001000,35"AngebotSumme = AngebotSumme.Replace(","".")
     DimnumberAsDouble = CDbl(AngebotSumme)
     Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de")
    AngebotSumme = Format("#,###.00"number)

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    Monday, September 23, 2013 8:38 AM
  • This Line

    AngebotSumme = Format("###,###,###.00", number)

    will give me not the 1000er Points back in my Field AngebotSumme

    The Result in the TextField is

    "   1000,35"...

    Best Regards

    Bernd

    Monday, September 23, 2013 9:03 AM
  • Dim AngebotSumme As String = "0001000,35"
            AngebotSumme = AngebotSumme.Replace(","".")
            Dim number As Double = CDbl(AngebotSumme)
            Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de")
            AngebotSumme = String.Format("{0:#,###.00}"number)
            Console.WriteLine(AngebotSumme)

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    Monday, September 23, 2013 9:17 AM
  • Try to keep yourself with your question it was about a problem with ##,# not with points.

    But if you look at my first reply you should be able to do that yourself. Otherwise, stop programming.


    Success
    Cor


    Monday, September 23, 2013 9:45 AM
  • I become only strings from any other Software and i must Format the strings correct...

    You can't adequately format a string.

    Convert those strings as supplied from that other application to numbers using (for instance) Decimal.TryParse:

    http://msdn.microsoft.com/en-us/library/9zbda557.aspx

    Use those numbers within your application as required.  When you need to convert them back to strings, use the appropriate string format method:

    http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

    Any other approach is just going to get more and more complicated as you try to handle the different conditions you will find in those strings.

    • Proposed as answer by Armin Zingler Monday, September 23, 2013 12:19 PM
    • Marked as answer by Carl Cai Friday, October 4, 2013 3:08 AM
    Monday, September 23, 2013 10:46 AM
  • @Bernd Riemke
       Have you checked my answer?I think that fits you very well. 
       Welcome your feedback, if you don't think that makes you feel well, please continue your replies or feedback about your questions in details.
       Another thing that I wanna point out is: Please be to pay attention to ONLY ONE point as much as possible. If you insist asking many questions related to each other, don't forget to mark answers or replies immediately;)

    @Cor Ligthert
       As an MVP, we'd better be patient to our customers to maintain our reputation;) I've to say that——
       @Otherwise, stop programming.
       It's very very rude:(

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report


    • Edited by ThankfulHeart Tuesday, September 24, 2013 3:28 AM Modify a wrong name
    Tuesday, September 24, 2013 3:19 AM
  • @ThankfulHeart,


    If somebody is driving a car and does't know where the brake is, I tell that it is better to stop driving.

    You probably tell to use the far most right pedal 

    That kind of replies is what I find rude.

    And please don't misquote, my statement started with an If, you simply have abused me now telling that I wrote something completely out of context. 

    An Please if you are an MVP, then use your name and don't hide yourself behind a Nick. 

    jmo
    Cor


    • Edited by Cor Ligthert Tuesday, September 24, 2013 8:47 AM
    Tuesday, September 24, 2013 8:44 AM