Method
decimal
(
&self,
character: PyStrRef,
default: OptionalArg<PyObjectRef>,
vm: &VirtualMachine,
)
Source from the content-addressed store, hash-verified
| 274 | |
| 275 | #[pymethod] |
| 276 | fn decimal( |
| 277 | &self, |
| 278 | character: PyStrRef, |
| 279 | default: OptionalArg<PyObjectRef>, |
| 280 | vm: &VirtualMachine, |
| 281 | ) -> PyResult { |
| 282 | let ch = self.extract_char(character, vm)?.and_then(|c| c.to_char()); |
| 283 | if let Some(ch) = ch |
| 284 | && ch.numeric_type() == Some(NumericType::Decimal) |
| 285 | && let Some(Number::Integer(n)) = ch.numeric_value() |
| 286 | { |
| 287 | return Ok(vm.ctx.new_int(n).into()); |
| 288 | } |
| 289 | default.ok_or_else(|| vm.new_value_error("not a decimal")) |
| 290 | } |
| 291 | |
| 292 | #[pymethod] |
| 293 | fn numeric( |