Question: I am working on Jasper Reports using IReport. I want to convert the amount to Words such as 1500 to One thousand five hundred.

I retrieve the numbers from the database and print it on the report. At the end I want the final value to be converted to Words.

Is there any method in Jasper Reports to do this? I have found a Java class to do that. If there's any method in Jasper report, how can I call Java method from jasper report to convert the numbers to letters

Answer: 
This might do the trick but it is hard to know with such a limited sample:

```
def format(s)
  s.sub(/\A(.*?:\s*\d+\(\d+\))/) { $1 + "\n" }
end

```

The main thing that looks for is `': 61(97)'` and `': 76(160)'` or, generally, a colon followed by zero or more whitespace characters followed by a number followed by a number within parentheses.

If you don't know how many entries are on each line then you can use [`scan`](https://ruby-doc.org/core/String.html#method-i-scan) to extract them and [`join`](https://ruby-doc.org/core/Array.html#method-i-join) to put them back together:

```
def format(s)
  s.scan(/.*?:\s*\d+\(\d+\)/).join("\n")
end

```

for example:

```
>> s = str1 + str2
=> "M Rahim (C)(W): 61(97)S A Hasan: 51(68)R Taylor (C): 76(160)B Watling: 16(26)"
>> s.scan(/.*?:\s*\d+\(\d+\)/).join("\n")
=> "M Rahim (C)(W): 61(97)\nS A Hasan: 51(68)\nR Taylor (C): 76(160)\nB Watling: 16(26)"

```
```
def format(string)
  string.sub(/(\d\))/, '\1' + "\n")
end

p format("M Rahim (C)(W): 61(97)S A Hasan: 51(68)") #=> "M Rahim (C)(W): 61(97)\nS A Hasan: 51(68)"
p format("R Taylor (C): 76(160)B Watling: 16(26)")  #=> "R Taylor (C): 76(160)\nB Watling: 16(26)"

```