Change Dot in Float to Comma

blaufasan's icon

Hi folks,
simple question, but hard to solve.

example:

theres a floatnum, eg. 3.132 . now i want to print that
floatnum but i dont wanna print 3.132, i wanna print 3,132.

i just want to substitute the dot with the comma.

thanks for your help,
kind regards

Georg Hajdu's icon

Does the result have to be printed by flonum or would an abstraction/bpatcher using textedit or lcd be sufficient?

Tim Lloyd's icon

I'm not sure why, but I can't get regexp to do this properly. It should be a really simple *regexp "(\.) @substitute ,"* but it won't replace with the comma..........anything else in place of the comma works fine.

*regexp (\.) @substitute why_won't_this_work* for example.....

Hopefully someone with more regexp experience will explain why that is, because I must be doing it wrong.

For the record, I've tried *regexp (\.) "@substitute ,"* and *regexp (\.) @substitute ,* as well the latter of which includes the backslash in the substitution, however no backslash results in an automatic correction to @substitute, which will also not work.

Sorry to not be of more help, this should be simple to sort out!

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.

This is a surprisingly hard problem in many languages, further complicated by the fact that commas are special characters in in Max (and many languages.)

Luke Hall's icon

You might want to try [prepend set]-ing it into a comment rather than a message box if it is only for display purposes as comments don't have to obey all the tricky max laws that messages do.

lh

Tim Lloyd's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Right you are Luke:

Roman Thilenius's icon

slice it, then replace the dot with the comma using ascii (atoi and itoa)

Christopher Dobrian's icon
Max Patch
Copy patch and select New From Clipboard in Max.
keepsound's icon
Max Patch
Copy patch and select New From Clipboard in Max.

With all the above examples you get an error on decimal points beginning with a zero. Beginning zeroes are all truncated.
And there's a space after the comma, so you get two symbols and not a unique one

metamax's icon

With all the above examples you get an error on decimal points beginning with a zero

Max Patch
Copy patch and select New From Clipboard in Max.

Sébastien's icon

Hi there!
To make this short I want to get rid of a comma at the end of a message that is set with regexp @substitute. It's a long shot but I am trying to work around a boolean restriction with the maxurl object and the json format. See https://cycling74.com/forums/remove-reverse-solidus-quotation-mark-message-dict-serialize-mode-json-dict-pack

But I get stuck with a comma at the end of my instruction.
ThatLastComma: { "on":true, "hue":33333, "sat":200, "bri":127, }
How can I get rid of the last comma? Thank you.

Max Patch
Copy patch and select New From Clipboard in Max.

metamax's icon

You seem to be adding the comma at the end of your regexp argument. Try removing \\, from the end of the expression.

Sébastien's icon

The thing of it is that I need commas to separate the value pairs, but the last one gives me a json format error with the maxurl object. I trying to figure out a way to iterate it only three times.

keepsound's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Try this:

metamax's icon

OK, I think I understand.

regexp (.+)\\, will give you everything before the last comma, out the 2nd outlet. Then all you have to do is append a bracket at the end and you got it. Like this:

Max Patch
Copy patch and select New From Clipboard in Max.

Sébastien's icon

Hi METAMAX!
Nice regexp! I reordered the object flow and It does exactly what I need.Thanks!

Max Patch
Copy patch and select New From Clipboard in Max.

metamax's icon

Good to hear, my friend. All the best with your project.

Francesco Gagliardi's icon

Best Solution is [regexp \\. @substitute \\,]

keepsound's icon