With the new FormatNumber() function in PB 5.50, PureBasic introduces a configurable decimal point character.
For the consistency: Why these optional DecimalPoint$ parameter is not added to the Str*() functions?
Result$ = FormatNumber(Number.d [, NbDecimals [, DecimalPoint$ [, ThousandSeperator$]]])
Result$ = StrF(Value.f [, NbDecimal [, DecimalPoint$]])
Result$ = StrD(Value.d [, NbDecimal [, DecimalPoint$]])
Would be nice if the current DecimalPoint$ could be interpreted also by the ValF() and ValD() function...
Result.f = ValF(String$ [, DecimalPoint$])
Result.d = ValD(String$ [, DecimalPoint$])
Alternative:
A function like SetDecimalPoint(DecimalPoint$) to set the decimal point character for all conversion functions (FormatNumber, StrF, StrD, ValF, ValD) globally. Default value is "."
Optional DecimalPoint$ for StrF() and StrD()
Optional DecimalPoint$ for StrF() and StrD()
Last edited by Lebostein on Wed Jan 25, 2017 2:26 pm, edited 2 times in total.
Re: Optional DecimalPoint$ for StrF() and StrD()
That's why.Lebostein wrote:Result.f = ValF(String$ , DecimalPoint$])

Re: Optional DecimalPoint$ for StrF() and StrD()
What's the point? Sure you understood the problem?Dude wrote:That's why.Lebostein wrote:Result.f = ValF(String$ , DecimalPoint$])
12.35 = ValF("12.35")
12.35 = ValF("12,35", ",")
https://en.wikipedia.org/wiki/Decimal_m ... imal_point
https://en.wikipedia.org/wiki/Decimal_m ... imal_comma
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Optional DecimalPoint$ for StrF() and StrD()
Wouldn't it make everything a little bit slower?
How to handle the case StrF(123.456,",") where you don't use the decimals parameter?
And what about the group delimiter (for thousands)?
And signs, exponents, currency symbols etc.?
Would just write my own routines depending on what is needed...
How to handle the case StrF(123.456,",") where you don't use the decimals parameter?
And what about the group delimiter (for thousands)?
And signs, exponents, currency symbols etc.?
Would just write my own routines depending on what is needed...
Code: Select all
Procedure.s MyStrF(value.f,decimals=-1,point.s=".")
If decimals<0
ProcedureReturn ReplaceString(StrF(value),".",point)
Else
ProcedureReturn ReplaceString(StrF(value,decimals),".",point)
EndIf
EndProcedure
Macro MyValF(value,point=".")
ReplaceString(value,".",point,#PB_String_InPlace)
EndMacro
s.s=StrF(#PI)
t.s=MyStrF(#PI,5,",")
Debug StrF(#PI)
Debug MyStrF(#PI)
Debug MyStrF(#PI,2)
Debug MyStrF(#PI,5,",")
Debug ""
Debug ValF(s)
Debug MyValF(s)
Debug MyValF(t)
Debug MyValF(t,",")
Re: Optional DecimalPoint$ for StrF() and StrD()

I am here for the consistency. If Fred introduces a decimal point character then he should add this parameter to all conversion functions.
Re: Optional DecimalPoint$ for StrF() and StrD()
How can a float (number) also be a string? That's what you're requesting. It's impossible.Lebostein wrote:What's the point?
Re: Optional DecimalPoint$ for StrF() and StrD()
thats obviously not what he was requesting:
Result.f = ValF("1.23"); = 1.23
Result.f = ValF("1.23", "."); = 1.23
Result.f = ValF("1,23", ","); = 1.23
c ya,
nco2k
Result.f = ValF("1.23"); = 1.23
Result.f = ValF("1.23", "."); = 1.23
Result.f = ValF("1,23", ","); = 1.23
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Re: Optional DecimalPoint$ for StrF() and StrD()
@nco2k, I understand now what Lebostein means.
But in his first post, he posted this as an example:
Which was not obvious at all that he wanted to replace something in String$ with DecimalPoint$. It looked like he wanted to replace the result with a different decimal character, instead of formatting String$ to strip it first. You can interpret it either way.
Anyway, I get it now. Sorry for my misunderstanding.
But in his first post, he posted this as an example:
Code: Select all
Result.f = ValF(String$ [, DecimalPoint$])

Anyway, I get it now. Sorry for my misunderstanding.