I have word document in that use a zero before the decimal in numbers less than 1.
Please find the below attachment.
Expeceted_Number_output.docx (12.3 KB)
Input_Number.docx (12.3 KB)
I have word document in that use a zero before the decimal in numbers less than 1.
Please find the below attachment.
Expeceted_Number_output.docx (12.3 KB)
Input_Number.docx (12.3 KB)
@Princeshivananjappa The code is similar to what I have suggested to your colleague in this thread:
https://forum.aspose.com/t/i-word-document-in-that-i-need-to-use-commas-rather-than-spaces-in-numbers-over-9999/254348
You should slightly modify the regular expression and number format code:
Document doc = new Document(@"C:\Temp\in.docx");
FindReplaceOptions opt = new FindReplaceOptions();
opt.ReplacingCallback = new NumberFormatter();
doc.Range.Replace(new Regex(@"\.?\d+(\s\d+)*(\.\d+)?"), "", opt);
doc.Save(@"C:\Temp\out.docx");
private class NumberFormatter : IReplacingCallback
{
public ReplaceAction Replacing(ReplacingArgs args)
{
double number = double.Parse(args.Match.Value.Replace(" ", ""));
// Note number formatting depends on the culture.
CultureInfo info = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
args.Replacement = number.ToString("#,##0.####");
Thread.CurrentThread.CurrentCulture = info;
return ReplaceAction.Replace;
}
}