Jump to content

Stringformat Question


Marc
 Share

Recommended Posts

Hi,

just a question about the stringformat command: is it possible to achive the... ehrm, dunno the correct word, in german we would call it "tausenderzeichen"?

I have a value, let's say 123456790.

To make reading easier, I want to put it out as 1.234.567.890 (or 1,234,567,890 if you prefer).

Can this be achieved using stringformat?

Just curious, already wrote my own function to achieve this goal. Only want to know whether I wrote this function for nothing or not :whistle:

cu

Marc

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

I believe that string formatting was in a previous discussion, however I don't remember if anybody made any scripts to do the formatting. Below is a very simple string formatting function that I made. You should be able to modify it to whatever format you desire:

MsgBox(0, "Test", FormatNumber("1234567890", ".", 3))
Exit

Func FormatNumber($RawNum, $SepChar, $SegLen)
  $ComNum = ""
  If $SepChar = "" Then $SepChar = ","
  If $SegLen < 0 Then $SegLen = 3
  While (StringLen($RawNum) > $SegLen)
    $RawNum_len = StringLen($RawNum)
    $ComNum = $SepChar & StringMid($RawNum, $RawNum_len - ($SegLen - 1), $SegLen) & $ComNum
    $RawNum = StringTrimRight($RawNum, $SegLen)
  Wend
  $ComNum = $RawNum & $ComNum
  return $ComNum
EndFunc

Hope this helps! :whistle:

Link to comment
Share on other sites

Interesting function :whistle:

But, as I said: already wrote my own function. Just wanted to know if it could be done just using StringFormat B)

cu

Marc

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

Interesting function  :whistle:

But, as I said: already wrote my own function. Just wanted to know if it could be done just using StringFormat  B)

cu

Marc

I think so.

You have to use the flag field see the doc.

The doc is a cut and paste from windows/C spec perhaps we should put more example

Just exercise you will see the power of StringFormat

Link to comment
Share on other sites

More examples in the docu would be nice B)

Tried to figure it out using the current docu, but it did not really work out the way I wanted. Perhaps it's my fault, because I simply hate C/C++ language.... :whistle:

Next time better luck...

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...