I have this code ( which is not working unfortunately):
object Number
{
case class Number(number: Float)
def fromString(value: String): Either[Throwable, Number] =
{
Try("%.2f".format(value).replace(',', '.').toFloat)
.map(Number)
.toEither
}
}
def main(args: Array[String]): Unit = Number.fromString("100,555")
my goal is to have a Float, that looks like this:
100.56
But for now the output is:
Left(java.util.IllegalFormatConversionException: f != java.lang.String)
So my questin is: How can I get my wanted output?
Or is there a function to format and round a number like number_format in PHP