How to manually parse a floating point number from a string

前端 未结 11 1481
攒了一身酷
攒了一身酷 2020-12-02 15:35

Of course most languages have library functions for this, but suppose I want to do it myself.

Suppose that the float is given like in a C or Java program (except for

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 16:04

    Using a state machine. It's fairly easy to do, and even works if the data stream is interrupted (you just have to keep the state and the partial result). You can also use a parser generator (if you're doing something more complex).

提交回复
热议问题